expanded class INTEGER_8

Features exported to INTERNALS_HANDLER

8 bits signed integer.

Direct parents

conformant parents

INTEGER_GENERAL

Summary

exported features

Conversions:

Conversions:

Bitwise Logical Operators:

Object Printing:

Miscellaneous:

For experts only: native operators with potential untrapped overflow (no protection):

Details

to_integer_16: INTEGER_16

Explicit conversion to INTEGER_16.

ensure

  • Current = Result

to_integer_32: INTEGER

Explicit conversion to INTEGER_32.

ensure

  • Current = Result

to_integer: INTEGER

Explicit conversion to INTEGER_32.

ensure

  • Current = Result

to_integer_64: INTEGER_64

Explicit conversion to INTEGER_64.

ensure

  • Current = Result

to_real_32: REAL_32

Explicit conversion to REAL_32.

to_real_64: REAL

Explicit conversion to REAL_64.

to_number: NUMBER

Explicit conversion to NUMBER.

ensure

  • Result @= Current

hexadecimal_digit: CHARACTER

Gives the corresponding CHARACTER for range 0..15.

require

  • in_range(0, 15)

ensure

  • (once "0123456789ABCDEF").has(Result)

hash_code: INTEGER

The hash-code value of Current.

ensure

  • good_hash_value: Result >= 0

sqrt: REAL

Square root of Current.

require

  • Current >= 0

log: REAL

Natural Logarithm of Current.

require

  • Current > 0

log10: REAL

Base-10 Logarithm of Current.

require

  • Current > 0

+ (other: INTEGER_8): INTEGER_8

Sum with other (commutative).

require

  • no_overflow: Current > 0 = (other > 0) implies Current #+ other > 0 = (Current > 0)

    this means: if operand are of same sign, it will be sign of the Result.

ensure

  • Result #- other = Current

- (other: INTEGER_8): INTEGER_8

Result of substracting other.

require

  • no_overflow: Current > 0 /= (other > 0) implies Current #- other > 0 = (Current > 0)

    this means: if operand are of different sign, sign of the Result will be the same sign as Current.

ensure

  • Result #+ other = Current

* (other: INTEGER_8): INTEGER_8

Product by other.

require

  • no_overflow: divisible(other) implies Current #* other #// other = Current

ensure

  • Current /= 0 and other /= 0 implies Result /= 0
  • Result /= 0 implies Result #// other = Current
  • Result /= 0 implies Result #\\ other = 0

/ (other: INTEGER_8): REAL

Division by other.

require

  • other /= Void
  • divisible(other)

// (other: INTEGER_8): INTEGER_8

Quotient of the euclidian division of Current by other. The corresponding remainder is given by infix "\\".

See also infix "#//".

require

  • divisible(other)
  • no_overflow: other = -1 implies Current = 0 or Current |<< 1 /= 0

ensure

  • euclidian_divide_case1: Current >= 0 implies Result * other + Current \\ other = Current
  • euclidian_divide_case2: Current < 0 implies Result #* other #+ (Current \\ other) = Current

#// (other: INTEGER_8): INTEGER_8

Integer division of Current by other.

According to the ANSI C99: if Current and other are both non-negative, the Result is the quotient of the euclidian division; but this is not the general case, the Result value is the algebraic quotient Current/other with any fractional part discarded. (This is often called "truncated toward zero"). So, the corresponding remainder value only verify the expression remainder.abs < other.abs.

See also infix "//", infix "#\\".

require

  • divisible(other)

ensure

  • Result * other + Current #\\ other = Current
  • ansi_c_remainder: (Current - Result * other).abs < other.abs
  • ansi_c_good_case: Current >= 0 and other > 0 implies Current - Result * other >= 0

\\ (other: INTEGER_8): INTEGER_8

Remainder of the euclidian division of Current by other. By definition, 0 <= Result < other.abs.

See also infix "#\\", infix "//".

require

  • divisible(other)

ensure

  • Result >= 0
  • other |<< 1 /= 0 implies Result < other.abs
  • good_remainder: Result #- (Current #\\ other) #\\ other = 0

#\\ (other: INTEGER_8): INTEGER_8

Remainder of the integer division of Current by other. According to the ANSI C99:

  * if Current and other are both non-negative,
    the Result is the remainder of the euclidian division.
  * but this is not the general case,
    Result as the same sign as Current and only verify
    the expression Result.abs < other.abs.
See also infix "\\", infix "#//".

require

  • divisible(other)

ensure

  • (Current - Result) #\\ other = 0
  • ansi_c_remainder: Result.abs < other.abs
  • ansi_c_good_case: Current >= 0 and other > 0 implies Result >= 0

^ (exp: INTEGER_8): INTEGER_64

Integer power of Current by other

require

  • exp >= 0

abs: INTEGER_8

Absolute value of Current.

require

  • not_minimum_value: Current = 0 or else Current |<< 1 /= 0

ensure

  • Result >= 0

< (other: INTEGER_8): BOOLEAN

Is Current strictly less than other?

See also >, <=, >=, min, max.

require

  • other_exists: other /= Void

ensure

  • asymmetric: Result implies not (other < Current)

<= (other: INTEGER_8): BOOLEAN

require

  • other_exists: other /= Void

ensure

  • definition: Result = (Current < other or is_equal(other))

> (other: INTEGER_8): BOOLEAN

require

  • other_exists: other /= Void

ensure

  • definition: Result = (other < Current)

>= (other: INTEGER_8): BOOLEAN

require

  • other_exists: other /= Void

ensure

  • definition: Result = (other <= Current)

+: INTEGER_8

Unary plus of Current.

-: INTEGER_8

Unary minus of Current.

require

  • not_minimum_value: Current < 0 implies 0 < #-Current

is_odd: BOOLEAN

Is odd?

is_even: BOOLEAN

Is even?

gcd (other: INTEGER_8): INTEGER_8

Great Common Divisor of Current and other.

ensure

  • Result >= 0
  • Result = 0 implies Current = 0 and other = 0
  • Result >= 2 implies Current \\ Result = 0 and other \\ Result = 0 and (Current // Result).gcd(other // Result) = 1

to_string: STRING

The decimal view of Current into a new allocated STRING. For example, if Current is -1 the Result is "-1".

See also append_in, to_string_format, to_unicode_string, to_hexadecimal, to_octal.

to_unicode_string: UNICODE_STRING

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, to_hexadecimal, to_octal.

to_boolean: BOOLEAN

Return False for 0, otherwise True.

See also to_string, to_character, to_hexadecimal, to_number.

ensure

  • Result = (Current /= 0)

append_in (buffer: STRING)

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)

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

to_string_format (s: INTEGER): STRING

Same as to_string but the result is on s character and the number is right aligned.

See also append_in_format, to_character, to_number, to_hexadecimal.

require

  • to_string.count <= s

ensure

  • Result.count = s

to_unicode_string_format (s: INTEGER): UNICODE_STRING

Same as to_unicode_string but the result is on s character and the number is right aligned.

See also append_in_unicode_format, to_string, to_hexadecimal, to_octal.

require

  • to_string.count <= s

ensure

  • Result.count = s

append_in_format (buffer: STRING, s: INTEGER)

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, to_hexadecimal_in.

require

  • to_string.count <= s

ensure

  • buffer.count >= old buffer.count + s

append_in_unicode_format (buffer: UNICODE_STRING, s: INTEGER)

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, to_hexadecimal_in.

require

  • to_string.count <= s

ensure

  • buffer.count >= old buffer.count + s

decimal_digit: CHARACTER

Gives the corresponding CHARACTER for range 0..9.

require

  • in_range(0, 9)

ensure

  • (once "0123456789").has(Result)
  • Current.is_equal(Result.value)

digit: CHARACTER

Gives the corresponding CHARACTER for range 0..9.

require

  • in_range(0, 9)

ensure

  • (once "0123456789").has(Result)
  • Current.is_equal(Result.value)

to_character: CHARACTER

Return the coresponding ASCII character.

See also to_boolean, to_number, to_string, to_hexadecimal.

require

  • Current >= 0

to_octal_in (buffer: STRING)

Append in the buffer the equivalent of to_octal. If you look for performances, you should always prefer to_octal_in which allow you to recycle a unique common buffer (each call of to_octal allocate a new object!).

See also to_hexadecimal_in, append_in, append_in_format, append_in_unicode.

ensure

  • buffer.count = old buffer.count + (object_size * 8) #// 3 + 1

to_octal: STRING

The octal view of Current into a new allocated STRING. For example, if Current is -1 and if Current is a 16 bits integer the Result is "177777".

See also to_octal_in, to_hexadecimal, to_number, to_string.

ensure

  • Result.count = (object_size * 8) #// 3 + 1

to_hexadecimal: STRING

The hexadecimal view of Current into a new allocated STRING. For example, if Current is -1 and if Current is a 32 bits integer the Result is "FFFFFFFF".

See also to_hexadecimal_in, to_octal, to_number, to_string.

ensure

  • Result.count = object_size * 2

to_hexadecimal_in (buffer: STRING)

Append in the buffer the equivalent of to_hexadecimal. If you look for performances, you should always prefer to_hexadecimal_in which allow you to recycle a unique common buffer (each call of to_hexadecimal allocate a new object!).

See also to_octal_in, append_in, append_in_format, append_in_unicode.

ensure

  • buffer.count = old buffer.count + object_size * 2

bit_test (idx: INTEGER_8): BOOLEAN

The value of the idx-ith bit (the right-most bit is at index 0).

require

  • idx >= 0
  • idx < object_size * 8

bit_set (idx: INTEGER_8): INTEGER_8

The value of the idx-ith bit (the right-most bit is at index 0).

require

  • idx >= 0
  • idx < object_size * 8

ensure

  • Result.bit_test(idx)
  • Result = Current or Result.bit_reset(idx) = Current

bit_reset (idx: INTEGER_8): INTEGER_8

The value of the idx-ith bit (the right-most bit is at index 0).

require

  • idx >= 0
  • idx < object_size * 8

ensure

  • not Result.bit_test(idx)
  • Result = Current or Result.bit_set(idx) = Current

|>> (s: INTEGER_8): INTEGER_8

Shift by s positions right (sign bit copied) bits falling off the end are lost.

require

  • s >= 0

bit_shift_right (s: INTEGER_8): INTEGER_8

Shift by s positions right (sign bit copied) bits falling off the end are lost.

require

  • s >= 0

|>>> (s: INTEGER_8): INTEGER_8

Shift by s positions right (sign bit not copied) bits falling off the end are lost.

require

  • s >= 0

bit_shift_right_unsigned (s: INTEGER_8): INTEGER_8

Shift by s positions right (sign bit not copied) bits falling off the end are lost.

require

  • s >= 0

|<< (s: INTEGER_8): INTEGER_8

Shift by s positions left bits falling off the end are lost.

require

  • s >= 0

bit_shift_left (s: INTEGER_8): INTEGER_8

Shift by s positions left bits falling off the end are lost.

require

  • s >= 0

#>> (s: INTEGER_8): INTEGER_8

Rotate by s positions right.

require

  • s > 0
  • s < object_size * 8

bit_rotate_right (s: INTEGER_8): INTEGER_8

Rotate by s positions right.

require

  • s > 0
  • s < object_size * 8

#<< (s: INTEGER_8): INTEGER_8

Rotate by s positions left.

require

  • s > 0
  • s < object_size * 8

bit_rotate_left (s: INTEGER_8): INTEGER_8

Rotate by s positions left.

require

  • s > 0
  • s < object_size * 8

bit_rotate (s: INTEGER_8): INTEGER_8

Rotate by s positions (positive s shifts right, negative left

See also infix "#>>" and infix "#<<".

require

  • s > -object_size * 8
  • s < object_size * 8

~: INTEGER_8

One's complement of Current.

bit_not: INTEGER_8

One's complement of Current.

& (other: INTEGER_8): INTEGER_8

Bitwise logical and of Current with other.

bit_and (other: INTEGER_8): INTEGER_8

Bitwise logical and of Current with other.

| (other: INTEGER_8): INTEGER_8

Bitwise logical inclusive or of Current with other.

bit_or (other: INTEGER_8): INTEGER_8

Bitwise logical inclusive or of Current with other.

bit_xor (other: INTEGER_8): INTEGER_8

Bitwise logical exclusive or of Current with other.

bit_shift (s: INTEGER_8): INTEGER_8

Shift by s positions (positive s shifts right (sign bit copied), negative shifts left bits falling off the end are lost).

See also infix "|>>" and infix "|<<".

require

  • s /= 0

bit_shift_unsigned (s: INTEGER_8): INTEGER_8

Shift by s positions (positive s shifts right (sign bit not copied), negative left bits falling off the end are lost).

See also infix "|>>>" and infix "|<<".

require

  • s /= 0

out_in_tagged_out_memory

Append terse printable represention of current object in tagged_out_memory.

ensure

  • 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

Append a viewable information in tagged_out_memory in order to affect the behavior of out, tagged_out, etc.

sign: INTEGER_8

Sign of Current (0 or -1 or 1).

ensure

  • -1 <= Result
  • Result <= 1

one: INTEGER_8

Neutral element for "*" and "/".

zero: INTEGER_8

Neutral element for "+" and "-".

divisible (other: INTEGER_8): BOOLEAN

May Current be divided by other ?

require

  • other /= Void

is_equal (other: INTEGER_8): BOOLEAN

Is other attached to an object considered equal to current object ?

require

  • other /= Void

ensure

  • trichotomy: Result = (not (Current < other) and not (other < Current))
  • commutative: generating_type = other.generating_type implies Result = other.is_equal(Current)
  • Result implies hash_code = other.hash_code

is_a_power_of_2: BOOLEAN

Is Current a power of 2?

require

  • Current > 0

#+ (other: INTEGER_8): INTEGER_8
#-: INTEGER_8
#- (other: INTEGER_8): INTEGER_8
#* (other: INTEGER_8): INTEGER_8
deferred is_equal (other: INTEGER_8): BOOLEAN

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)

is_equal (other: INTEGER_8): BOOLEAN

Is other attached to an object considered equal to current object ?

require

  • other /= Void

ensure

  • trichotomy: Result = (not (Current < other) and not (other < Current))
  • commutative: generating_type = other.generating_type implies Result = other.is_equal(Current)

in_range (lower: INTEGER_8, upper: INTEGER_8): BOOLEAN

Return True if Current is in range [lower..upper]

See also min, max, compare.

ensure

  • Result = (Current >= lower and Current <= upper)

compare (other: INTEGER_8): INTEGER

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: INTEGER_8): INTEGER

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: INTEGER_8): INTEGER_8

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: INTEGER_8): INTEGER_8

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