Explorer

definy.float-literal

description
The float(mantissa, exponent) literal of value: the fewest decimal digits (up to 17) that give the value exactly (call with scale 1 and exponent 0)
type
Fn(value: Float, scale: Number, exponent: Number) -> Record{mantissa: Number, exponent: Number}
expression
fn(value$0, scale$1, exponent$2) =>
  let scaled$3 = @core.float-multiply(left: $0, right: @core.float-from-integer(value: $1));
  let truncated$4 = @core.float-truncate(value: $3);
  let back$5 = @core.float-from-integer(value: $4);
  match @core.or(
      left: @core.greater-than-or-equal(left: $2, right: 17),
      right: @core.not(
        value: @core.or(
          left: @core.float-less-than(left: $5, right: $3),
          right: @core.float-less-than(left: $3, right: $5)
        )
      )
    ) {
    true =>
      {mantissa: $4, exponent: @core.minus(left: 0, right: $2)},
    false =>
      @definy.float-literal(value: $0, scale: @core.multiply(left: $1, right: 10), exponent: @core.plus(left: $2, right: 1))
  }
visibility
public
definy.float-literal (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: auTgKUwc7FzvuSgnfrui6YyS13sigt2hEIULRAEG3T4
content hash: mR_9iQTfpFOuP-F_81d83xMU8ORGKAO3IQJ80jNhtkg