core :: Numeric :: defaultinit
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Comparable :: defaultinit
core :: Numeric :: defaultinit
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# A numeric value supporting mathematical operations
interface Numeric
super Comparable
redef type OTHER: Numeric
# Addition of `self` with `i`
fun +(i: OTHER): OTHER is abstract
# Substraction of `i` from `self`
fun -(i: OTHER): OTHER is abstract
# Inverse of `self`
fun -: OTHER is abstract
# Multiplication of `self` with `i`
fun *(i: OTHER): OTHER is abstract
# Division of `self` with `i`
fun /(i: OTHER): OTHER is abstract
# The integer part of `self`.
#
# assert (0.0).to_i == 0
# assert (0.9).to_i == 0
# assert (-0.9).to_i == 0
# assert (9.9).to_i == 9
# assert (-9.9).to_i == -9
fun to_i: Int is abstract
# The float equivalent of `self`
#
# assert 5.to_f == 5.0
# assert 5.to_f != 5 # Float and Int are not equals
fun to_f: Float is abstract
# The byte equivalent of `self`
#
# assert (-1).to_b == 0xFF.to_b
# assert (1.9).to_b == 1.to_b
fun to_b: Byte is abstract
# Is this the value of zero in its domain?
fun is_zero: Bool do return self == zero
# The value of zero in the domain of `self`
fun zero: OTHER is abstract
# The value of `val` in the domain of `self`
#
# assert 1.0.value_of(2) == 2.0
# assert 1.0.value_of(2.0) == 2.0
# assert 1.value_of(2) == 2
# assert 1.value_of(2.0) == 2
fun value_of(val: Numeric): OTHER is abstract
end
lib/core/kernel.nit:431,1--486,3
redef class Numeric
# The Int8 equivalent of `self`
#
# assert (-1).to_i8 == 0xFFFFi8
# assert (1.9).to_i8 == 1i8
fun to_i8: Int8 do return self.to_i.to_i8
# The Int16 equivalent of `self`
#
# assert (-1).to_i16 == 0xFFFFi16
# assert (1.9).to_i16 == 1i16
fun to_i16: Int16 do return self.to_i.to_i16
# The UInt16 equivalent of `self`
#
# assert (-1).to_u16 == 0xFFFFu16
# assert (1.9).to_u16 == 1u16
fun to_u16: UInt16 do return self.to_i.to_u16
# The Int32 equivalent of `self`
#
# assert (-1).to_i32 == 0xFFFFFFFFi32
# assert (1.9).to_i32 == 1i32
fun to_i32: Int32 do return self.to_i.to_i32
# The UInt32 equivalent of `self`
#
# assert (-1).to_u32 == 0xFFFFFFFFu32
# assert (1.9).to_u32 == 1u32
fun to_u32: UInt32 do return self.to_i.to_u32
end
lib/core/fixed_ints.nit:43,1--75,3
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
lib/core/numeric.nit:43,1--83,3