class

Hwaro::Assets::Sass::Number

Inherits Hwaro::Assets::Sass::Value < Reference < Object

Constants

EPSILON = 1e-11

dart-sass treats numbers within 1e-11 of each other as equal (0.1 * 3 == 0.3); floor/ceil/round are exact there.

PRECISE_SPELLING = /\d[eE][+-]?\d|\.\d{11}/
UNIT_CONVERSIONS = {"px" => {0, 1.0}, "cm" => {0, 96.0 / 2.54}, "mm" => {0, 96.0 / 25.4}, "q" => {0, 96.0 / 101.6}, "in" => {0, 96.0}, "pt" => {0, 4.0 / 3.0}, "pc" => {0, 16.0}, "deg" => {1, 1.0}, "grad" => {1, 0.9}, "rad" => {1, 180.0 / Math::PI}, "turn" => {1, 360.0}, "s" => {2, 1.0}, "ms" => {2, 0.001}, "hz" => {3, 1.0}, "khz" => {3, 1000.0}, "dppx" => {4, 1.0}, "dpi" => {4, 1.0 / 96.0}, "dpcm" => {4, 2.54 / 96.0}}

Convertible-unit groups (dart-sass's known compatibilities): {group id, factor to the group's canonical unit}. Lookup is case-insensitive because CSS units are.

Constructors

new(value : Float64, unit : String = "", lexeme : String | Nil = nil)
Source

Class methods

conversion_factor(from : String, to : String) : Float64 | Nil

Multiplier that converts a value in from units to to units; nil when the units aren't in the same convertible group.

Source
format(value : Float64) : String

dart-sass-style number formatting: integers without a decimal point, floats rounded to 10 digits with trailing zeros trimmed.

Never routes through Float64#to_s, which switches to exponent form outside roughly [1e-4, 1e16). CSS has no exponent syntax and no Infinity/NaN literals, so 3.33333e-5px is not a number a browser can read — it drops the whole declaration. Small values are reachable from ordinary ratio math (opacity, scale).

Source
fuzzy_eq?(a : Float64, b : Float64) : Bool

dart-sass fuzzyEquals: within epsilon AND the same value once scaled and rounded, so 0.4e-11 and 0.6e-11 stay distinct.

Source
fuzzy_le?(a : Float64, b : Float64) : Bool
Source
fuzzy_lt?(a : Float64, b : Float64) : Bool
Source
precise_spelling?(text : String) : Bool

True for number text only full-precision storage produces (an exponent, or more than ten fractional digits). Read back, such a number formats like a computed one instead of echoing its lexeme.

Source

Instance methods

coerce_value(other : Number) : Float64

The other operand's value expressed in THIS number's unit (the left operand of an arithmetic expression wins the unit, dart-sass semantics). Callers must have checked compatible_unit?.

Source
compatible_unit?(other : Number) : Bool

Identical units, one side unitless, or units in the same convertible group (px↔in, deg↔turn, s↔ms, ...).

Source
eq?(other : Value) : Bool

Sass equality (==). Subclasses override; default is identity on serialized text.

Source
inspect_css(storage : Bool = false) : String

Storage keeps every bit of a computed number. The ten-digit CSS spelling turned a running $factor: $factor * 0.1 into 0 after eleven steps (Foundation's long-division divide() returned 0px for 10px / 3) and let rounding error pile up across loops. The precise spelling is never emitted: see precise_spelling?.

Source
int_value(context : String) : Int32
Source
lexeme

Original source spelling (".5em"); kept so uncomputed numbers serialize byte-identically.

Source
result_unit(other : Number) : String
Source
to_css

CSS text for this value (what lands in output).

Source
unit
Source
value
Source