@haxall/haxall
    Preparing search index...

    Class Number

    Number represents a numeric value and an optional Unit.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    type$: Type

    Methods

    • Return absolute value of this number.

      Returns Number

    • Return if this number is approximately equal to that - see sys::Float.approx

      Parameters

      • that: Number
      • Optionaltolerance: number

      Returns boolean

    • Clamp this number between the min and max. If its less than min then return min, if its greater than max return max, otherwise return this number itself. The min and max must have matching units or be unitless. The result is always in the same unit as this instance.

      Parameters

      Returns Number

    • Compare is based on val. Throw UnitErr is this and b have incompatible units.

      Parameters

      Returns number

    • Decrement this number. Shortcut is --a.

      Returns Number

    • Divide this by b. Shortcut is a/b. The resulting unit is derived from the quotient of this and b. Throw UnitErr if a/b does not match a unit in the unit database.

      Parameters

      Returns Number

    • Equality is based on val and unit. NaN is equal to itself (like Float.compare, but unlike Float.equals)

      Parameters

      Returns boolean

    • Hash is based on val

      Returns number

    • Increment this number. Shortcut is ++a.

      Returns Number

    • Does this number have a time unit which can be converted to a Fantom Duration instance.

      Returns boolean

    • Return if this Obj is immutable and safe to share between threads:

      • an instance of a const class
      • the result of toImmutable on List, Map, or Buf
      • a Func object may or may not be immutable - see sys::Func.
      • other instances are assumed mutable and return false

      Returns boolean

    • Is this number a whole integer without a fractional part

      Returns boolean

    • Is the floating value NaN.

      Returns boolean

    • Is this a negative number

      Returns boolean

    • Return if this number if pos/neg infinity or NaN

      Returns boolean

    • Get the ASCII lower case version of this number as a Unicode point.

      Returns Number

    • Return max value. Units are not checked for this comparison.

      Parameters

      Returns Number

    • Return min value. Units are not checked for this comparison.

      Parameters

      Returns Number

    • Subtract b from this. Shortcut is a-b. The b.unit must match this.unit.

      Parameters

      Returns Number

    • Return remainder of this divided by b. Shortcut is a%b. The unit of b must be null.

      Parameters

      Returns Number

    • Multiple this and b. Shortcut is ab. The resulting unit is derived from the product of this and b. Throw UnitErr if ab does not match a unit in the unit database.

      Parameters

      Returns Number

    • Negate this number. Shortcut is -a.

      Returns Number

    • Add this with b. Shortcut is a+b. Throw UnitErr is this and b have incompatible units.

      Parameters

      Returns Number

    • Trio/zinc code representation, same as toStr

      Returns string

    • Get this number as a Fantom Duration instance

      Parameters

      • Optionalchecked: boolean

      Returns Duration

    • Get the scalar value as an Float

      Returns number

    • Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:

      • if type is const, return this
      • if already an immutable List, Map, Buf, or Func return this
      • if a List, then attempt to perform a deep clone by calling toImmutable on all items
      • if a Map, then attempt to perform a deep clone by calling toImmutable on all values (keys are already immutable)
      • some Funcs can be made immutable - see sys::Func
      • if a Buf create immutable copy, see sys::Buf
      • any other object throws NotImmutableErr

      Returns Readonly<this>

    • Get the scalar value as an Int

      Returns number

    • Format the number using given pattern which is an superset of sys::Float.toLocale:

      #        optional digit
      0 required digit
      . decimal point
      , grouping separator (only last one before decimal matters)
      U position of unit (default to suffix)
      pos;neg separate negative format (must specify U position)

      When using the pos;neg pattern, the "U" position must be specified in both pos and neg patterns, otherwise the unit is omitted. Note that the negative pattern always uses mimics the positive pattern for the actual digit formatting (#, 0, decimal, and grouping).

      The special "B" pattern is used to format bytes; see sys::Int.toLocale.

      If pattern is null, the following rules are used:

      1. If isDuration true, then return best fit unit is selected
      2. If unit is non-null attempt to lookup a unit specific default pattern with the locale key "haystack::number.{unit.name}".
      3. If isInt true, then return sys::Int.toLocale using sys locale default
      4. Return sys::Float.toLocale using sys locale default

      Examples:

      Number   Pattern        Result    Notes
      ------ ------- ------- ------
      12.34 "#.####" 12.34 Optional fractional digits
      12.34 "#.0000" 12.3400 Required fractional digits
      12.34$ null $12.34 Haystack locale default
      12$ "U 0.00" $ 12.00 Explicit unit placement
      -12$ "U0.##;(U#)" ($12) Alternative negative format
      45% "+0.0U;-0.0U" +45% Use leading positive sign

      Parameters

      • Optionalpattern: string

      Returns string

    • String representation

      Returns string

    • Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:

      a->x        a.trap("x", null)
      a->x() a.trap("x", null)
      a->x = b a.trap("x", [b])
      a->x(b) a.trap("x", [b])
      a->x(b, c) a.trap("x", [b, c])

      The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.

      Parameters

      Returns JsObj

    • Get the Type instance which represents this object's class. Also seeType.of or Pod.of.

      Returns Type

    • Get unit associated with this number or null.

      Returns Unit

    • Get the ASCII upper case version of this number as a Unicode point.

      Returns Number

    • This method called whenever an it-block is applied to an object. The default implementation calls the function with this, and then returns this.

      Parameters

      • f: (arg0: this) => void

      Returns this

    • Default value is zero with no unit

      Returns Number

    • Write x.toStr to standard output followed by newline. If x is null then print "null". If no argument is provided then print an empty line.

      Parameters

      Returns void

    • Parse from a string according to zinc syntax

      Parameters

      • s: string
      • Optionalchecked: boolean
      • ...args: unknown[]

      Returns Number

    • Construct from scalar value and optional unit.

      Parameters

      • val: number
      • Optionalunit: Unit
      • ...args: unknown[]

      Returns Number

    • Construct from a duration, standardize unit is hours If unit is null, then a best attempt is made based on magnitude.

      Parameters

      Returns Number

    • Construct from scalar integer and optional unit.

      Parameters

      • val: number
      • Optionalunit: Unit
      • ...args: unknown[]

      Returns Number

    • Construct from scalar Int, Float, or Decimal and optional unit.

      Parameters

      • val: number
      • Optionalunit: Unit

      Returns Number

    • Constant for not-a-number

      Returns Number

    • Constant for negative infinity

      Returns Number

    • Constant for -1 with no unit

      Returns Number

    • Constant for 1 with no unit

      Returns Number

    • Constant for positive infinity

      Returns Number

    • Constant for 10 with no unit

      Returns Number

    • Constant for 0 with no unit

      Returns Number