iyi

Prelude, 0.18.0

Int32

The comparison cross is the one UInt16 joins, and only it: the conversions above stay at five, because std/int declares the whole tower's conversions and a prelude that also declared UInt16#to_i32 would be redefining one of them (SPEC.md R-3, which is how this split announced itself).

In the prelude: every iyi program has it, with no import.

A wide character against a double is left out for the same reason and a better one: std/int defines that comparison by converting, because every value narrower than a double is a double exactly, and an instruction that compares the two directly is not what it means. A 64-bit one is not, and the instruction rounded it first: 9007199254740993_i64 == 9007199254740992.0 was true. Split at 2048, its high part is a double exactly, and the difference below keeps the values' sign.

Int32struct

Int32iyi doc Int32
struct Int32 < Int

  def !=(other : Int32) : Bool

  def !=(other : Int64) : Bool

  def !=(other : UInt8) : Bool

  def !=(other : UInt64) : Bool

  def !=(other : Float64) : Bool

  def !=(other : UInt16) : Bool

  def %(other : Int32) : Int32

  def &(other : Int32) : self

  def &(other : Int64) : self

  def &(other : UInt8) : self

  def &(other : UInt64) : self

  def &*(other : Int32) : self

  def &*(other : Int64) : self

  def &*(other : UInt8) : self

  def &*(other : UInt64) : self

  def &+(other : Int32) : self

  def &+(other : Int64) : self

  def &+(other : UInt8) : self

  def &+(other : UInt64) : self

  def &-(other : Int32) : self

  def &-(other : Int64) : self

  def &-(other : UInt8) : self

  def &-(other : UInt64) : self

  def *(other : Int32) : self

  def *(other : Int64) : self

  def *(other : UInt8) : self

  def *(other : UInt64) : self

  def *(other : Float64) : Float64

  # A whole power, by squaring: `2 ** 10`. A negative exponent is a
  # mistake for an integer, as division by zero is.
  def **(exponent : Int32) : Int32

  def +(other : Int32) : self

  def +(other : Int64) : self

  def +(other : UInt8) : self

  def +(other : UInt64) : self

  def +(other : Float64) : Float64

  def -(other : Int32) : self

  def -(other : Int64) : self

  def -(other : UInt8) : self

  def -(other : UInt64) : self

  def -(other : Float64) : Float64

  def - : Int32

  def /(other : Float64) : Float64

  # The zero is checked here rather than left to the processor. `1 // 0` used
  # to reach `unsafe_div`, trap, and kill the program with "Process terminated
  # because of a floating-point system exception" — an integer division
  # reported by the operating system as a floating-point fault, which is a
  # sentence nobody can act on.
  def //(other : Int32) : Int32

  def <(other : Int32) : Bool

  def <(other : Int64) : Bool

  def <(other : UInt8) : Bool

  def <(other : UInt64) : Bool

  def <(other : Float64) : Bool

  def <(other : UInt16) : Bool

  # Shifts, and the magnitude: what a bit of arithmetic past the four
  # operators asks for first. A shift by the width or more answers zero (the
  # sign, for a negative shifted right), which the processor does not
  # promise, and a negative count shifts the other way, as `8 >> -2` is 32.
  def <<(count : Int32) : Int32

  def <=(other : Int32) : Bool

  def <=(other : Int64) : Bool

  def <=(other : UInt8) : Bool

  def <=(other : UInt64) : Bool

  def <=(other : Float64) : Bool

  def <=(other : UInt16) : Bool

  def ==(other : Int32) : Bool

  def ==(other : Int64) : Bool

  def ==(other : UInt8) : Bool

  def ==(other : UInt64) : Bool

  def ==(other : Float64) : Bool

  def ==(other : UInt16) : Bool

  def >(other : Int32) : Bool

  def >(other : Int64) : Bool

  def >(other : UInt8) : Bool

  def >(other : UInt64) : Bool

  def >(other : Float64) : Bool

  def >(other : UInt16) : Bool

  def >=(other : Int32) : Bool

  def >=(other : Int64) : Bool

  def >=(other : UInt8) : Bool

  def >=(other : UInt64) : Bool

  def >=(other : Float64) : Bool

  def >=(other : UInt16) : Bool

  def >>(count : Int32) : Int32

  def ^(other : Int32) : self

  def ^(other : Int64) : self

  def ^(other : UInt8) : self

  def ^(other : UInt64) : self

  def abs : Int32

  # The character with this code point: the other half of `Char#ord`.
  def chr : Char

  def even? : Bool

  def hash : Int32

  def odd? : Bool

  def times(& : (Int32 -> Nil)) : Nil

  def to_f : Float64

  def to_f64 : Float64

  # The checked form raises on overflow — which in this prelude is a panic,
  # since `__crystal_raise_overflow` prints and exits (SPEC.md III.1.4).
  #
  # The unchecked form is the conversion without the check, and a float
  # past the range saturates (NaN is 0), alike in every build. It is
  # spelled the way `unsafe_chr` below is: `unsafe_to_u8`. Crystal spells
  # it `to_u8!`, which is not a name in iyi (SPEC.md III.1.7) — those
  # declarations were accepted only because a macro expansion was
  # reparsed by the other language's rules, and no iyi source could call
  # one: `x.to_u8!` is `x.to_u8` with its error propagated. The callers
  # wanted the instruction: `memset`'s `value.to_u8!` is C's "converted to
  # unsigned char", and the checked form panics on 0x1ff where C writes 0xff.
  def to_i : Int32

  def to_i32 : Int32

  def to_i64 : Int64

  def to_s(base : Int32) : String

  def to_s : String

  def to_u64 : UInt64

  def to_u8 : UInt8

  def unsafe_chr : Char

  def unsafe_div(other : Int32) : self

  def unsafe_div(other : Int64) : self

  def unsafe_div(other : UInt8) : self

  def unsafe_div(other : UInt64) : self

  def unsafe_mod(other : Int32) : self

  def unsafe_mod(other : Int64) : self

  def unsafe_mod(other : UInt8) : self

  def unsafe_mod(other : UInt64) : self

  def unsafe_shl(other : Int32) : self

  def unsafe_shl(other : Int64) : self

  def unsafe_shl(other : UInt8) : self

  def unsafe_shl(other : UInt64) : self

  def unsafe_shr(other : Int32) : self

  def unsafe_shr(other : Int64) : self

  def unsafe_shr(other : UInt8) : self

  def unsafe_shr(other : UInt64) : self

  def unsafe_to_f : Float64

  def unsafe_to_f64 : Float64

  def unsafe_to_i : Int32

  def unsafe_to_i32 : Int32

  def unsafe_to_i64 : Int64

  def unsafe_to_u64 : UInt64

  def unsafe_to_u8 : UInt8

  def |(other : Int32) : self

  def |(other : Int64) : self

  def |(other : UInt8) : self

  def |(other : UInt64) : self

  def self.zero : self
end