+
Point of view
All features
deferred class NATURAL_GENERAL
Summary
General natural number abstraction to share common code for NATURAL_8, NATURAL_16, NATURAL_32 and NATURAL_64.
All implementations have a limited size (8, 16, 32 or 64 bits). As NATURAL_8, NATURAL_16, NATURAL_32 and NATURAL_64 are expanded classes, it is not possible to expect any form of polymorphism (but you are sure to get the very best execution speed).
See also INTEGER_8, INTEGER_16, INTEGER_32, INTEGER_64, NUMBER or MUTABLE_BIG_INTEGER.
Direct parents
Inherit list: COMPARABLE, HASHABLE
Insert list: PLATFORM
Known children
Insert list: NATURAL_16, NATURAL_32, NATURAL_64, NATURAL_8
Overview
Features
{ANY}
  • infix "+" (other: NATURAL_GENERAL): NATURAL_GENERAL
    Sum with other (commutative).
  • infix "-" (other: NATURAL_GENERAL): NATURAL_GENERAL
    Result of subtracting other.
  • infix "*" (other: NATURAL_GENERAL): NATURAL_GENERAL
    Product by other.
  • infix "/" (other: NATURAL_GENERAL): REAL_64
    Division by other.
  • infix "//" (other: NATURAL_GENERAL): NATURAL_GENERAL
    Quotient of the Euclidian division of Current by other.
  • infix "\\" (other: NATURAL_GENERAL): NATURAL_GENERAL
    Remainder of the Euclidian division of Current by other.
  • infix "<" (other: NATURAL_GENERAL): BOOLEAN
    Is Current strictly less than other?
  • infix "<=" (other: NATURAL_GENERAL): BOOLEAN
    Is Current less than or equal other?
  • infix ">" (other: NATURAL_GENERAL): BOOLEAN
    Is Current strictly greater than other?
  • infix ">=" (other: NATURAL_GENERAL): BOOLEAN
    Is Current greater than or equal than other?
  • is_odd: BOOLEAN
    Is odd?
  • is_even: BOOLEAN
    Is even?
  • is_equal (other: NATURAL_GENERAL): BOOLEAN
    Is other attached to an object considered equal to current object?
Conversions:
{ANY}
Modular arithmetic (these wrap around on overflow)
{ANY}
  • infix "#+" (other: NATURAL_GENERAL): NATURAL_GENERAL
  • infix "#-" (other: NATURAL_GENERAL): NATURAL_GENERAL
  • infix "#\\" (other: NATURAL_GENERAL): NATURAL_GENERAL
  • infix "#//" (other: NATURAL_GENERAL): NATURAL_GENERAL
Object printing
{ANY}
Bitwise Logical Operators:
{ANY}
  • infix "#>>" (s: INTEGER_8): NATURAL_GENERAL
    Rotate by s positions right.
  • bit_rotate_right (s: INTEGER_8): NATURAL_GENERAL
    Rotate by s positions right.
  • infix "#<<" (s: INTEGER_8): NATURAL_GENERAL
    Rotate by s positions left.
  • bit_rotate_left (s: INTEGER_8): NATURAL_GENERAL
    Rotate by s positions left.
  • bit_rotate (s: INTEGER_8): NATURAL_GENERAL
    Rotate by s positions (positive s shifts right, negative left
  • prefix "~": NATURAL_GENERAL
    One's complement of Current.
  • bit_not: NATURAL_GENERAL
    One's complement of Current.
  • infix "&" (other: NATURAL_GENERAL): NATURAL_GENERAL
    Bitwise logical and of Current with other.
  • bit_and (other: NATURAL_GENERAL): NATURAL_GENERAL
    Bitwise logical and of Current with other.
  • infix "|" (other: NATURAL_GENERAL): NATURAL_GENERAL
    Bitwise logical inclusive or of Current with other.
  • bit_or (other: NATURAL_GENERAL): NATURAL_GENERAL
    Bitwise logical inclusive or of Current with other.
  • bit_xor (other: NATURAL_GENERAL): NATURAL_GENERAL
    Bitwise logical exclusive or of Current with other.
  • infix "|>>" (s: INTEGER_8): NATURAL_GENERAL
    Shift by s positions right (sign bit copied) bits falling off the end are lost.
  • bit_shift_right (s: INTEGER_8): NATURAL_GENERAL
    Shift by s positions right (sign bit copied) bits falling off the end are lost.
  • infix "|<<" (s: INTEGER_8): NATURAL_GENERAL
    Shift by s positions left bits falling off the end are lost.
  • bit_shift_left (s: INTEGER_8): NATURAL_GENERAL
    Shift by s positions left bits falling off the end are lost.
Size query
{ANY}
{}
{ANY}
  • in_range (lower: NATURAL_GENERAL, upper: NATURAL_GENERAL): BOOLEAN
    Return True if Current is in range [lower..upper]
    See also min, max, compare.
  • compare (other: NATURAL_GENERAL): INTEGER_32
    If current object equal to other, 0 if smaller, -1; if greater, 1.
  • three_way_comparison (other: NATURAL_GENERAL): INTEGER_32
    If current object equal to other, 0 if smaller, -1; if greater, 1.
  • min (other: NATURAL_GENERAL): NATURAL_GENERAL
    Minimum of Current and other.
  • max (other: NATURAL_GENERAL): NATURAL_GENERAL
    Maximum of Current and other.
  • bounded_by (a_min: NATURAL_GENERAL, a_max: NATURAL_GENERAL): NATURAL_GENERAL
    A value that is equal to Current if it is between the limits set by a_min and a_max.
{ANY}
Maximum:
{}
Minimum:
{}
Bits:
{}
infix "+" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
Sum with other (commutative).
infix "-" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
Result of subtracting other.
infix "*" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
Product by other.
infix "/" (other: NATURAL_GENERAL): REAL_64
{ANY}
Division by other.
infix "//" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
Quotient of the Euclidian division of Current by other.
The corresponding remainder is given by infix "\\".
See also infix "#//".
infix "\\" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
Remainder of the Euclidian division of Current by other.
By definition, 0 <= Result < other.abs.
See also infix "#\\", infix "//".
infix "<" (other: NATURAL_GENERAL): BOOLEAN
{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: NATURAL_GENERAL): BOOLEAN
{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: NATURAL_GENERAL): BOOLEAN
{ANY}
Is Current strictly greater than other?
See also <, >=, <=, min, max.
require
  • other_exists: other /= Void
ensure
  • definition: Result = other < Current
infix ">=" (other: NATURAL_GENERAL): BOOLEAN
{ANY}
Is Current greater than or equal than other?
See also <=, >, <, min, max.
require
  • other_exists: other /= Void
ensure
  • definition: Result = other <= Current
is_odd: BOOLEAN
deferred function
{ANY}
Is odd?
is_even: BOOLEAN
deferred function
{ANY}
Is even?
is_equal (other: NATURAL_GENERAL): BOOLEAN
effective function
{ANY}
Is other attached to an object considered equal to current object?
require
    • other /= Void
    • other /= Void
ensure
  • commutative: generating_type = other.generating_type implies Result = other.is_equal(Current)
  • trichotomy: Result = not Current < other and not other < Current
  • Result implies hash_code = other.hash_code
to_string: STRING
effective function
{ANY}
The decimal view of Current into a new allocated STRING.
For example, if Current is 3 the Result is "3".
See also append_in, to_string_format, to_unicode_string.
to_unicode_string: UNICODE_STRING
effective function
{ANY}
The decimal view of Current into a new allocated UNICODE_STRING.
For example, if Current is -1 the Result is U"-1".
See also append_in_unicode, to_unicode_string_format, to_string.
append_in_format (buffer: STRING, s: INTEGER_32)
effective procedure
{ANY}
Append in the buffer the equivalent of to_string_format.
If you look for performances, you should always prefer append_in_format which allow you to recycle a unique common buffer (each call of to_string_format allocate a new object!).
See also append_in, append_in_unicode, append_in_unicode_format.
require ensure
  • buffer.count >= old buffer.count + s
append_in_unicode_format (buffer: UNICODE_STRING, s: INTEGER_32)
effective procedure
{ANY}
Append in the buffer the equivalent of to_unicode_string_format.
If you look for performances, you should always prefer append_in_unicode_format which allow you to recycle a unique common buffer (each call of to_unicode_string_format allocate a new object!).
See also append_in_format, append_in, append_in_format.
require ensure
  • buffer.count >= old buffer.count + s
decimal_digit: CHARACTER
deferred function
{ANY}
Gives the corresponding CHARACTER for range 0..9.
See also hexadecimal_digit.
ensure
  • "0123456789".has(Result)
hexadecimal_digit: CHARACTER
deferred function
{ANY}
Gives the corresponding CHARACTER for range 0..15.
See also decimal_digit.
ensure
  • "0123456789ABCDEF".has(Result)
to_character: CHARACTER
deferred function
{ANY}
Return the corresponding ASCII character.
See also to_boolean, to_number, to_string.
to_number: NUMBER
deferred function
{ANY}
Convert Current into a new allocated NUMBER.
See also to_boolean, to_string, to_character, to_hexadecimal.
ensure
infix "#+" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
infix "#-" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
infix "#\\" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
infix "#//" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
out_in_tagged_out_memory
effective procedure
{ANY}
Append terse printable representation of current object in tagged_out_memory.
require
    • locked: tagged_out_locked
    • locked: tagged_out_locked
ensure
  • still_locked: tagged_out_locked
  • not_cleared: tagged_out_memory.count >= old tagged_out_memory.count
  • append_only: old tagged_out_memory.twin.is_equal(tagged_out_memory.substring(1, old tagged_out_memory.count))
fill_tagged_out_memory
effective procedure
{ANY}
Append a viewable information in tagged_out_memory in order to affect the behavior of out, tagged_out, etc.
require
    • locked: tagged_out_locked
    • locked: tagged_out_locked
ensure
  • still_locked: tagged_out_locked
to_hexadecimal: STRING
effective function
{ANY}
to_hexadecimal_in (buffer: STRING)
effective procedure
{ANY}
append_in (buffer: STRING)
deferred procedure
{ANY}
Append in the buffer the equivalent of to_string.
If you look for performances, you should always prefer append_in which allow you to recycle a unique common buffer (each call of to_string allocate a new object!).
See also append_in_format, append_in_unicode, append_in_unicode_format, to_hexadecimal_in.
require
  • buffer /= Void
append_in_unicode (buffer: UNICODE_STRING)
deferred procedure
{ANY}
Append in the buffer the equivalent of to_unicode_string.
If you look for performances, you should always prefer append_in_unicode which allow you to recycle a unique common buffer (each call of to_unicode_string allocate a new object!).
See also append_in_unicode_format, append_in, append_in_format, to_hexadecimal_in.
require
  • buffer /= Void
infix "#>>" (s: INTEGER_8): NATURAL_GENERAL
{ANY}
Rotate by s positions right.
See also bit_rotate_left and bit_rotate.
require
bit_rotate_right (s: INTEGER_8): NATURAL_GENERAL
{ANY}
Rotate by s positions right.
See also bit_rotate_left and bit_rotate.
require
infix "#<<" (s: INTEGER_8): NATURAL_GENERAL
{ANY}
Rotate by s positions left.
require
bit_rotate_left (s: INTEGER_8): NATURAL_GENERAL
{ANY}
Rotate by s positions left.
require
bit_rotate (s: INTEGER_8): NATURAL_GENERAL
{ANY}
Rotate by s positions (positive s shifts right, negative left
See also bit_rotate_right and bit_rotate_left.
require
prefix "~": NATURAL_GENERAL
{ANY}
One's complement of Current.
bit_not: NATURAL_GENERAL
{ANY}
One's complement of Current.
infix "&" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
Bitwise logical and of Current with other.
bit_and (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
Bitwise logical and of Current with other.
infix "|" (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
Bitwise logical inclusive or of Current with other.
bit_or (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
Bitwise logical inclusive or of Current with other.
bit_xor (other: NATURAL_GENERAL): NATURAL_GENERAL
{ANY}
Bitwise logical exclusive or of Current with other.
infix "|>>" (s: INTEGER_8): NATURAL_GENERAL
{ANY}
Shift by s positions right (sign bit copied) bits falling off the end are lost.
bit_shift_right (s: INTEGER_8): NATURAL_GENERAL
{ANY}
Shift by s positions right (sign bit copied) bits falling off the end are lost.
infix "|<<" (s: INTEGER_8): NATURAL_GENERAL
{ANY}
Shift by s positions left bits falling off the end are lost.
bit_shift_left (s: INTEGER_8): NATURAL_GENERAL
{ANY}
Shift by s positions left bits falling off the end are lost.
bit_count: INTEGER_8
deferred function
{ANY}
The number of bits used to store the value of Current (it is 8 for NATURAL_8, 16 for NATURAL_16 and so on) This is actually used only for assertion here, in NATURAL_GENERAL.
ensure
string_buffer: STRING
once function
{}
unicode_string_buffer: UNICODE_STRING
once function
{}
in_range (lower: NATURAL_GENERAL, upper: NATURAL_GENERAL): 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: NATURAL_GENERAL): 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: NATURAL_GENERAL): 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: NATURAL_GENERAL): NATURAL_GENERAL
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: NATURAL_GENERAL): NATURAL_GENERAL
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: NATURAL_GENERAL, a_max: NATURAL_GENERAL): NATURAL_GENERAL
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)
hash_code: INTEGER_32
deferred function
{ANY}
The hash-code value of Current.
ensure
  • good_hash_value: Result >= 0
Maximum_character_code: INTEGER_16
{}
Largest supported code for CHARACTER values.
ensure
  • meaningful: Result >= 127
Maximum_integer_8: INTEGER_8
is 127
constant attribute
{}
Largest supported value of type INTEGER_8.
Maximum_integer_16: INTEGER_16
is 32767
constant attribute
{}
Largest supported value of type INTEGER_16.
Maximum_integer: INTEGER_32
is 2147483647
constant attribute
{}
Largest supported value of type INTEGER/INTEGER_32.
Maximum_integer_32: INTEGER_32
is 2147483647
constant attribute
{}
Largest supported value of type INTEGER/INTEGER_32.
Maximum_integer_64: INTEGER_64
is 9223372036854775807
constant attribute
{}
Largest supported value of type INTEGER_64.
Maximum_real_32: REAL_32
is {REAL_32 3.4028234663852885981170418348451692544e+38}
constant attribute
{}
Largest non-special (no NaNs nor infinity) supported value of type REAL_32.
Maximum_real: REAL_64
{}
Largest non-special (no NaNs nor infinity) supported value of type REAL.
Just to give an idea of this value: 1.79769313486231570....e+308
Maximum_real_64: REAL_64
{}
Largest non-special (no NaNs nor infinity) supported value of type REAL.
Just to give an idea of this value: 1.79769313486231570....e+308
Maximum_real_80: REAL_EXTENDED
{}
Largest supported value of type REAL_80.
ensure
Minimum_character_code: INTEGER_16
{}
Smallest supported code for CHARACTER values.
ensure
  • meaningful: Result <= 0
Minimum_integer_8: INTEGER_8
is -128
constant attribute
{}
Smallest supported value of type INTEGER_8.
Minimum_integer_16: INTEGER_16
is -32768
constant attribute
{}
Smallest supported value of type INTEGER_16.
Minimum_integer: INTEGER_32
is -2147483648
constant attribute
{}
Smallest supported value of type INTEGER/INTEGER_32.
Minimum_integer_32: INTEGER_32
is -2147483648
constant attribute
{}
Smallest supported value of type INTEGER/INTEGER_32.
Minimum_integer_64: INTEGER_64
is -9223372036854775808
constant attribute
{}
Smallest supported value of type INTEGER_64.
Minimum_real_32: REAL_32
is {REAL_32 -3.40282346638528859811704183484516925440e+38}
constant attribute
{}
Smallest non-special (no NaNs nor infinity) supported value of type REAL_32.
Minimum_real: REAL_64
{}
Smallest non-special (no NaNs nor infinity) supported value of type REAL.
Just to give an idea of this value: -1.79769313486231570....e+308
Minimum_real_64: REAL_64
{}
Smallest non-special (no NaNs nor infinity) supported value of type REAL.
Just to give an idea of this value: -1.79769313486231570....e+308
Minimum_real_80: REAL_64
{}
Smallest supported value of type REAL_80.
ensure
  • meaningful: Result <= 0.0
Boolean_bits: INTEGER_32
{}
Number of bits in a value of type BOOLEAN.
ensure
  • meaningful: Result >= 1
Character_bits: INTEGER_32
{}
Number of bits in a value of type CHARACTER.
ensure
Integer_bits: INTEGER_32
{}
Number of bits in a value of type INTEGER.
ensure
  • integer_definition: Result = 32
Real_bits: INTEGER_32
is 64
constant attribute
{}
Number of bits in a value of type REAL.
Pointer_bits: INTEGER_32
{}
Number of bits in a value of type POINTER.