+
Point of view
All features
deferred class FLOAT
Summary
This class defines the floating-point operations.
Direct parents
Inherit list: COMPARABLE, NUMERIC
Known children
Inherit list: REAL_GENERAL
Overview
Features
{ANY}
Conversions:
{ANY}
  • rounded: FLOAT
    Round to nearest integer away from zero.
  • floor: FLOAT
    Largest integral value no greater than Current.
  • ceiling: FLOAT
    Smallest integral value no smaller than Current.
Object Printing:
{ANY}
Maths functions:
{ANY}
  • sqrt: FLOAT
    Square root of Current.
  • sin: FLOAT
    Sine of Current.
  • cos: FLOAT
    Cosine of Current.
  • tan: FLOAT
    Tangent of Current.
  • asin: FLOAT
    Arc Sine of Current.
  • acos: FLOAT
    Arc Cosine of Current.
  • atan: FLOAT
    Arc Tangent of Current.
  • atan2 (x: FLOAT): FLOAT
    Arc Tangent of Current / x.
  • sinh: FLOAT
    Hyperbolic Sine of Current.
  • cosh: FLOAT
    Hyperbolic Cosine of Current.
  • tanh: FLOAT
    Hyperbolic Tangent of Current.
  • exp: FLOAT
    Exponential of Current.
  • log: FLOAT
    Natural Logarithm of Current.
  • log10: FLOAT
    Base-10 Logarithm of Current.
  • pow (e: FLOAT): FLOAT
    Current raised to the power of e (ANSI C pow).
Hashing:
{ANY}
Miscellaneous:
{ANY}
  • sign: INTEGER_8
    Sign of Current (0 -1 or 1).
  • mantissa_bits: INTEGER_8
    Give the number of bits, corresponding to the mantissa, in the binary representation of the real number.
  • exponent_bits: INTEGER_8
    Give the number of bits, corresponding to the exponent, in the binary representation of the real number.
{ANY}
  • prefix "+": FLOAT
    Unary plus of Current.
  • prefix "-": FLOAT
    Unary minus of Current.
  • one: FLOAT
    Neutral element for "*" and "/".
  • zero: FLOAT
    Neutral element for "+" and "-".
{ANY}
  • is_equal (other: FLOAT): BOOLEAN
    Is other attached to an object considered equal to current object?
{ANY}
  • infix "<" (other: FLOAT): BOOLEAN
    Is Current strictly less than other?
  • infix "<=" (other: FLOAT): BOOLEAN
    Is Current less than or equal other?
  • infix ">" (other: FLOAT): BOOLEAN
    Is Current strictly greater than other?
  • infix ">=" (other: FLOAT): BOOLEAN
    Is Current greater than or equal than other?
  • in_range (lower: FLOAT, upper: FLOAT): BOOLEAN
    Return True if Current is in range [lower..upper]
    See also min, max, compare.
  • compare (other: FLOAT): INTEGER_32
    If current object equal to other, 0 if smaller, -1; if greater, 1.
  • three_way_comparison (other: FLOAT): INTEGER_32
    If current object equal to other, 0 if smaller, -1; if greater, 1.
  • min (other: FLOAT): FLOAT
    Minimum of Current and other.
  • max (other: FLOAT): FLOAT
    Maximum of Current and other.
  • bounded_by (a_min: FLOAT, a_max: FLOAT): FLOAT
    A value that is equal to Current if it is between the limits set by a_min and a_max.
infix "+" (another: FLOAT): FLOAT
deferred function
{ANY}
Sum with other (commutative).
infix "-" (another: FLOAT): FLOAT
deferred function
{ANY}
Result of subtracting other.
infix "*" (another: FLOAT): FLOAT
deferred function
{ANY}
Product by other.
infix "/" (another: FLOAT): FLOAT
deferred function
{ANY}
Division by other.
require
  • another /= Void
  • another /= zero
  • divisible(another)
infix "^" (another: INTEGER_32): FLOAT
deferred function
{ANY}
Raise Current to e-th power (see also pow).
abs: FLOAT
deferred function
{ANY}
is_not_a_number: BOOLEAN
deferred function
{ANY}
Also known as NaN in IEEE-754.
is_infinity: BOOLEAN
deferred function
{ANY}
Is either plus or minus infinity?
is_zero: BOOLEAN
deferred function
{ANY}
Is either -0.0 or +0.0 ?
ensure
  • definition: Result = Current = zero or else Current = - zero
infix "~=" (other: FLOAT): BOOLEAN
deferred function
{ANY}
Is Current near equal to other.
is_subnormal: BOOLEAN
deferred function
{ANY}
Is it too small to be represented in normalized format.
ensure
  • Result = Current = zero or else Current = - zero
is_normal: BOOLEAN
deferred function
{ANY}
The most general situation (see ensure).
ensure
divisible (other: FLOAT): BOOLEAN
deferred function
{ANY}
May Current be divided by other ?
require
  • other /= Void
rounded: FLOAT
frozen
deferred function
{ANY}
Round to nearest integer away from zero.
floor: FLOAT
frozen
deferred function
{ANY}
Largest integral value no greater than Current.
ceiling: FLOAT
frozen
deferred function
{ANY}
Smallest integral value no smaller than Current.
to_string: STRING
deferred function
{ANY}
Convert Current into a new allocated STRING using 6 as the default number of digits for the fractional part.
Example: (1.5).to_string will return "1.500000".
Note: see also to_string_format, to_string_scientific as well as append_in to save memory.
to_string_format (f: INTEGER_32): STRING
deferred function
{ANY}
Convert Current into a new allocated STRING using f digits for fractional part.
Example: (1.5).to_string_format(2) will return "1.50".
Note: see also to_string_scientific, to_string as well as append_in_format to save memory.
require
  • f >= 0
to_string_scientific (f: INTEGER_32): STRING
deferred function
{ANY}
Convert Current into a new allocated STRING, using the scientific notation with f digits for the fractional part.
Example: (155.5).to_string_scientific(4) will return "1.5550e+02".
Note: see also to_string, to_string_format as well as append_in_scientific to save memory.
append_in (buffer: STRING)
deferred procedure
{ANY}
Append the equivalent of to_string at the end of buffer.
Thus you can save memory because no other STRING is allocated for the job.
require
  • buffer /= Void
append_in_format (str: STRING, f: INTEGER_32)
deferred procedure
{ANY}
Append the equivalent of to_string_format at the end of buffer.
Thus you can save memory because no other STRING is allocated for the job.
require
  • str /= Void
  • f >= 0
append_in_scientific (str: STRING, f: INTEGER_32)
deferred procedure
{ANY}
Append the equivalent of to_string_scientific at the end of buffer.
Thus you can save memory because no other STRING is allocated for the job.
require
  • str /= Void
  • f >= 0
sqrt: FLOAT
frozen
deferred function
{ANY}
Square root of Current.
require
sin: FLOAT
frozen
deferred function
{ANY}
Sine of Current.
cos: FLOAT
frozen
deferred function
{ANY}
Cosine of Current.
tan: FLOAT
frozen
deferred function
{ANY}
Tangent of Current.
asin: FLOAT
frozen
deferred function
{ANY}
Arc Sine of Current.
acos: FLOAT
frozen
deferred function
{ANY}
Arc Cosine of Current.
atan: FLOAT
frozen
deferred function
{ANY}
Arc Tangent of Current.
atan2 (x: FLOAT): FLOAT
frozen
deferred function
{ANY}
Arc Tangent of Current / x.
sinh: FLOAT
frozen
deferred function
{ANY}
Hyperbolic Sine of Current.
cosh: FLOAT
frozen
deferred function
{ANY}
Hyperbolic Cosine of Current.
tanh: FLOAT
frozen
deferred function
{ANY}
Hyperbolic Tangent of Current.
exp: FLOAT
frozen
deferred function
{ANY}
Exponential of Current.
log: FLOAT
frozen
deferred function
{ANY}
Natural Logarithm of Current.
log10: FLOAT
frozen
deferred function
{ANY}
Base-10 Logarithm of Current.
pow (e: FLOAT): FLOAT
frozen
deferred function
{ANY}
Current raised to the power of e (ANSI C pow).
hash_code: INTEGER_32
deferred function
{ANY}
The hash-code value of Current.
ensure
  • good_hash_value: Result >= 0
sign: INTEGER_8
deferred function
{ANY}
Sign of Current (0 -1 or 1).
ensure
  • Result.in_range(-1, 1)
mantissa_bits: INTEGER_8
deferred function
{ANY}
Give the number of bits, corresponding to the mantissa, in the binary representation of the real number.
exponent_bits: INTEGER_8
deferred function
{ANY}
Give the number of bits, corresponding to the exponent, in the binary representation of the real number.
prefix "+": FLOAT
deferred function
{ANY}
Unary plus of Current.
prefix "-": FLOAT
deferred function
{ANY}
Unary minus of Current.
one: FLOAT
deferred function
{ANY}
Neutral element for "*" and "/".
zero: FLOAT
deferred function
{ANY}
Neutral element for "+" and "-".
is_equal (other: FLOAT): BOOLEAN
deferred function
{ANY}
Is other attached to an object considered equal to current object?
require
  • other /= Void
ensure
  • Result implies hash_code = other.hash_code
  • commutative: generating_type = other.generating_type implies Result = other.is_equal(Current)
infix "<" (other: FLOAT): BOOLEAN
deferred function
{ANY}
Is Current strictly less than other?
See also >, <=, >=, min, max.
require
  • other_exists: other /= Void
ensure
  • asymmetric: Result implies not other < Current
infix "<=" (other: FLOAT): BOOLEAN
effective function
{ANY}
Is Current less than or equal other?
See also >=, <, >, min, max.
require
  • other_exists: other /= Void
ensure
  • definition: Result = Current < other or is_equal(other)
infix ">" (other: FLOAT): BOOLEAN
effective function
{ANY}
Is Current strictly greater than other?
See also <, >=, <=, min, max.
require
  • other_exists: other /= Void
ensure
  • definition: Result = other < Current
infix ">=" (other: FLOAT): BOOLEAN
effective function
{ANY}
Is Current greater than or equal than other?
See also <=, >, <, min, max.
require
  • other_exists: other /= Void
ensure
  • definition: Result = other <= Current
in_range (lower: FLOAT, upper: FLOAT): BOOLEAN
effective function
{ANY}
Return True if Current is in range [lower..upper]
See also min, max, compare.
ensure
  • Result = Current >= lower and Current <= upper
compare (other: FLOAT): INTEGER_32
effective function
{ANY}
If current object equal to other, 0 if smaller, -1; if greater, 1.
See also min, max, in_range.
require
  • other_exists: other /= Void
ensure
  • equal_zero: Result = 0 = is_equal(other)
  • smaller_negative: Result = -1 = Current < other
  • greater_positive: Result = 1 = Current > other
three_way_comparison (other: FLOAT): INTEGER_32
effective function
{ANY}
If current object equal to other, 0 if smaller, -1; if greater, 1.
See also min, max, in_range.
require
  • other_exists: other /= Void
ensure
  • equal_zero: Result = 0 = is_equal(other)
  • smaller_negative: Result = -1 = Current < other
  • greater_positive: Result = 1 = Current > other
min (other: FLOAT): FLOAT
effective function
{ANY}
Minimum of Current and other.
See also max, in_range.
require
  • other /= Void
ensure
  • Result <= Current and then Result <= other
  • compare(Result) = 0 or else other.compare(Result) = 0
max (other: FLOAT): FLOAT
effective function
{ANY}
Maximum of Current and other.
See also min, in_range.
require
  • other /= Void
ensure
  • Result >= Current and then Result >= other
  • compare(Result) = 0 or else other.compare(Result) = 0
bounded_by (a_min: FLOAT, a_max: FLOAT): FLOAT
effective function
{ANY}
A value that is equal to Current if it is between the limits set by a_min and a_max.
Otherwise it's a_min if Current is smaller or a_max if Current is greater It's a shortcut for Current.min(a_max).max(a_min) also known as "clamp" in the widespread C library Glib
ensure
  • correctness: Result.in_range(a_min, a_max)