Numeric
typescore :: union_find
union–find algorithm using an efficient disjoint-set data structurebucketed_game :: bucketed_game
Game framework with an emphasis on efficient event coordinationaccept_scroll_and_zoom
gamnit :: camera_control_android
Two fingers camera manipulation, pinch to zoom and slide to scrollgamnit :: camera_control_linux
Mouse wheel and middle mouse button to control camerapthreads :: concurrent_array_and_barrier
A basic usage example of the modulespthreads
and pthreads::cocurrent_collections
pthreads :: concurrent_collections
Introduces thread-safe concurrent collectionsserialization :: custom_serialization
Example of an ad hoc serializer that is tailored to transform business specific objects into customized representation.egl
, sdl
and x11
FileServer
action, which is a standard and minimal file server
cocoa :: foundation
The Foundation Kit provides basic Objective-C classes and structuresfunctional_types.nit
functional :: functional_types
This module provides functional type to represents various function forms.gtk :: gtk_assistant
gtk :: gtk_dialogs
HttpRequest
class and services to create it
app::http_request
main service AsyncHttpRequest
Serializable::inspect
to show more useful information
Iterator
.
actors :: mandelbrot
Example implemented from "The computer Language Benchmarks Game" - Mandelbrotmarkdown2 :: markdown_html_rendering
HTML rendering of Markdown documentsmarkdown2 :: markdown_latex_rendering
LaTeX rendering of Markdown documentsmarkdown2 :: markdown_man_rendering
Manpages rendering of Markdown documentsmarkdown2 :: markdown_md_rendering
Markdown rendering of Markdown documentsmore_collections :: more_collections
Highly specific, but useful, collections-related classes.mpi :: mpi_simple
curl :: native_curl
Binding of C libCurl which allow us to interact with network.app.nit
on Android using a custom Java entry point
nitcc_runtime :: nitcc_runtime
Runtime library required by parsers and lexers generated by nitccnlp :: nlp_server
glesv2 :: opengles2_hello_triangle
Basic example of OpenGL ES 2.0 usage using SDL 2performance_analysis :: performance_analysis
Services to gather information on the performance of events by categoriesrestful
annotation documented at lib/nitcorn/restful.nit
sax :: sax_locator
Interface for associating a SAX event with a document location.Locator
.
msgpack :: serialization_common
Serialization services forserialization_write
and serialization_read
serialization :: serialization_core
Abstract services to serialize Nit objects to different formatsdeserialize_json
and JsonDeserializer
serialize_to_json
and JsonSerializer
msgpack :: serialization_write
Serialize full Nit objects to MessagePack formatroot
to execute
agent_simulation
by refining the Agent class to make
socket :: socket_simple_server
Simple server example using a non-blockingTCPServer
EulerCamera
and App::frame_core_draw
to get a stereoscopic view
gamnit :: texture_atlas_parser
Tool to parse XML texture atlas and generated Nit code to access subtextures
# Advanced services for `Numeric` types
module numeric
import math
import text
redef class Text
# Get the numeric version of `self`
#
# require: `is_numeric`
#
# ~~~~
# assert "0".to_n == 0
# assert "0.0".to_n == 0.0
# assert ".12345".to_n == 0.12345
# assert "12345".to_n == 12345
# assert "".to_n == 0
# ~~~~
fun to_n: Numeric
do
if is_empty then return 0
if chars.has('.') then return to_f
return to_i
end
end
redef interface Numeric
# Universal `+` with any `Numeric`
#
# ~~~~
# assert 1.add(1) == 2
# assert 1.add(0.1) == 1.1
# assert 1.1.add(1.1) == 2.2
# assert 1.1.add(1) == 2.1
# ~~~~
fun add(other: Numeric): Numeric is abstract
# Universal `-` with any `Numeric`
#
# ~~~~
# assert 2.sub(1) == 1
# assert 1.sub(0.1) == 0.9
# assert 1.1.sub(0.1) == 1.0
# assert 2.1.sub(1) == 1.1
# ~~~~
fun sub(other: Numeric): Numeric is abstract
# Universal `/` with any `Numeric`
#
# ~~~~
# assert 8.div(2) == 4
# assert 4.div(0.5) == 8.0
# assert 1.1.div(0.1) == 11.0
# assert 2.2.div(2) == 1.1
# ~~~~
fun div(other: Numeric): Numeric is abstract
# Universal `*` with any `Numeric`
#
# ~~~~
# assert 2.mul(4) == 8
# assert 11.mul(0.1) == 1.1
# assert 11.1.mul(0.1) == 1.11
# assert 1.1.mul(4) == 4.4
# ~~~~
fun mul(other: Numeric): Numeric is abstract
end
redef universal Int
redef fun add(other)
do
if other isa Float then
return to_f + other
else
return self + other.as(Int)
end
end
redef fun sub(other)
do
if other isa Float then
return to_f - other
else
return self - other.as(Int)
end
end
redef fun mul(other)
do
if other isa Float then
return to_f * other
else
return self * other.as(Int)
end
end
redef fun div(other)
do
if other isa Float then
return to_f / other
else if other isa Int then
if other == 0 then return self.to_f / 0.0
return self / other
else abort
end
end
redef universal Float
redef fun add(other) do return self + other.to_f
redef fun sub(other) do return self - other.to_f
redef fun div(other) do return self / other.to_f
redef fun mul(other) do return self * other.to_f
end
lib/core/numeric.nit:17,1--129,3