{ This file implements the IEEE-754 single precision floating point number in FALSE.
  See <https://en.wikipedia.org/wiki/Single-precision_floating-point_format> for more information. }

)PAD)BINARY

{ [z]ip :: (mantissa, exp, sign) → (float)
  Take the sign bit, an exponent, and a fraction off the stack and ‘zip’ them, as it were, into a single 32-bit floating
  point number. }
[
  { *** Handling the fraction *** }
    { The fraction is at the top of the stack.
      Take only the first 23 bits of the fraction }
    8388607 &  { &(2^23 - 1) }

  { *** Handling the exponent *** }
    \  { Swap the float for the exponent }
    127 +  { Encode the exponent }
    { Take only the first 8 bits of the exponent }
    255 &  { &(2^8 - 1) }
    { Shift those eight bits 23 bits to the left }
    8388608 *  { *(2^23), the same as <<23 }
    |  { Combine the float and the exponent }

  { *** Handling the sign bit *** }
    { The value at the top of the stack is our float }
    { Swap the float for the sign bit }
    \
    { Look at the sign bit }
    [
      2147483647 ~ |  { |(2^31) }
    ]?
]z:

{ [u]nzip :: (float) → (sign, exp, mantissa)
  Take a float and extract the sign bit, exponent, and fraction. }
[
  { *** Handling the sign bit *** }
    { The value at the top of the stack is our float }
    $
      { float, float }
    2147483647 { 2^31 - 1 } ~
      { 2^31, float, float }
    $
      { 2^31, 2^31, float, float }
    @
      { float, 2^31, 2^31, float }
    &
    { If the sign bit is 2^31, push -1, otherwise push 0 }
    =$[1_]?~[0]?
      { sign, float }

  { *** Handling the exponent *** }
    \
      { float, sign }
    $
      { float, float, sign }
    2139095040 &
      { exp-iso, float, sign }
    8388608 /
    { Decode the exponent }
    127 -

  { *** Handling the fraction *** }
      { exp, float, sign }
    \
      { float, exp, sign }
    8388607 &  { 2^23 - 1 }
      { mantissa, exp, sign }
]u:

{ [n]eg :: (float) → (-float)
  Negate the float. }
[
  { float }
  u;!
  { mantissa, exp, sign }
  @
  { sign, mantissa, exp }
  ~
  { -sign, mantissa, exp }
  @@
  { mantissa, exp, -sign }
  z;!
  { -float }
]n:

{ [o]utput :: (float) → ()
  Print the float to the screen. }
[
  u;!
  { mantissa, exp, sign }
  @
  { sign, mantissa, exp }
  ['-,]?
  { mantissa, exp }
]o:

1_ 10 102 z;! $ n;!
