Skip to content

Commit

Permalink
Document the floating-point numbers spec (sass#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
Israel-4Ever committed Mar 23, 2023
1 parent 7523a6a commit ef37245
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
69 changes: 65 additions & 4 deletions source/documentation/modules/math.html.md.erb
Expand Up @@ -9,29 +9,90 @@ title: sass:math
<% function 'math.$e' do %>
<% impl_status dart: '1.25.0', libsass: false, ruby: false %>

Equal to the value of the [mathematical constant *e*][].
The closest 64-bit floating point approximation of the [mathematical constant
*e*][].

[mathematical constant *e*]: https://en.wikipedia.org/wiki/E_(mathematical_constant)

<% example(autogen_css: false) do %>
@debug math.$e; // 2.7182818285
===
@debug math.$e // 2.7182818285
@debug math.$e // 2.7182818285
<% end %>
<% end %>
<% function 'math.$epsilon' do %>
<% impl_status dart: '1.55.0', libsass: false, ruby: false %>

The difference between 1 and the smallest 64-bit floating point number greater
than 1 according to floating-point comparisons. Because of Sass numbers' [10
digits of precision](../values/numbers), in many cases this will appear to
be 0.
<% end %>
<% function 'math.$max-number' do %>
<% impl_status dart: '1.55.0', libsass: false, ruby: false %>

The maximum finite number that can be represented as a 64-bit floating point
number.

<% example(autogen_css: false) do %>
@debug math.$max-number; // 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
===
@debug math.$max-number // 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
<% end %>
<% end %>
<% function 'math.$max-safe-integer' do %>
<% impl_status dart: '1.55.0', libsass: false, ruby: false %>

The maximum integer `n` such that both `n` and `n + 1` can be precisely
represented as a 64-bit floating-point number.

<% example(autogen_css: false) do %>
@debug math.$max-safe-integer; // 9007199254740991
===
@debug math.$max-safe-integer // 9007199254740991
<% end %>
<% end %>
<% function 'math.$min-number' do %>
<% impl_status dart: '1.55.0', libsass: false, ruby: false %>

The smallest positive number that can be represented as a 64-bit floating
point number. Because of Sass numbers' [10 digits of
precision](../values/numbers), in many cases this will appear to be 0.
<% end %>
<% function 'math.$min-safe-integer' do %>
<% impl_status dart: '1.55.0', libsass: false, ruby: false %>

The minimum integer `n` such that both `n` and `n - 1` can be precisely
represented as a 64-bit floating-point number.

<% example(autogen_css: false) do %>
@debug math.$min-safe-integer; // -9007199254740991
===
@debug math.$min-safe-integer // -9007199254740991
<% end %>
<% end %>
<% function 'math.$pi' do %>
<% impl_status dart: '1.25.0', libsass: false, ruby: false %>

Equal to the value of the [mathematical constant *π*][].
The closest 64-bit floating point approximation of the [mathematical constant *π*][].

[mathematical constant *π*]: https://en.wikipedia.org/wiki/Pi

<% example(autogen_css: false) do %>
@debug math.$pi; // 3.1415926536
===
@debug math.$pi // 3.1415926536
@debug math.$pi // 3.1415926536
<% end %>
<% end %>

Expand Down
5 changes: 3 additions & 2 deletions source/documentation/values/numbers.html.md.erb
Expand Up @@ -51,8 +51,9 @@ been spotty, Sass always compiles it to fully expanded numbers.
forwards-compatibility.
<% end %>

Sass numbers support up to 10 digits of precision after the decimal point. This
means a few different things:
Sass numbers are represented internally as 64-bit floating point values. They
support up to 10 digits of precision after the decimal point when serialized to
CSS and for the purposes of equality. This means a few different things:

* Only the first ten digits of a number after the decimal point will be included
in the generated CSS.
Expand Down

0 comments on commit ef37245

Please sign in to comment.