Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistently use floating-point numbers everywhere #1802

Merged
merged 8 commits into from Sep 21, 2022
Merged

Conversation

nex3
Copy link
Contributor

@nex3 nex3 commented Sep 15, 2022

var result = fuzzyCheckRange(number, min, max);
if (result != null) return result;
throw RangeError.range(
number, min, max, name, "must be between $min and $max");
}

/// Return [num1] modulo [num2], using Sass's modulo semantics, which it
/// inherited from Ruby and which differ from Dart's.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention the more general names for each language's semantics here? Wikipedia says that Ruby/Sass uses floored division, while Dart uses Euclidean division.

Now that I think of it, it doesn't look like we define Sass's modulo semantics in the spec (either the existing ones or the floating point proposal). Should we do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! sass/sass#3393

/// digit.
bool fuzzyEquals(num number1, num number2) {
if (number1 == number2) return true;
// Using `!<=` here rather than `>` means we filter out `Infinity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this use <= and not !<= in the comment ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and isn't this missing a backtick at the end of the line ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is just no longer necessary.

lib/src/value/number.dart Outdated Show resolved Hide resolved
CHANGELOG.md Outdated
@@ -10,6 +31,10 @@
* Add an optional `argumentName` parameter to `SassScriptException()` to make it
easier to throw exceptions associated with particular argument names.

* Most APIs that previously returned `num` now return `double`. All APIs
continue to _accept_ `num`, although in Dart 2.0.0 most of these APIs will be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any insight about which APIs may be excluded here (the reason for saying most of in this sentence) ?

As I'm working on version 2 of scssphp (to make it fully spec compliant and easier to maintain), I think it would make sense that scssphp would use float (PHP's name for the double type) for arguments instead of float|int (which is the equivalent of Dart's num type), as we don't have existing consumers of those APIs yet for which we need to provide BC. So I'd like to know if there are some places for which I should not do the migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be safe to just use float everywhere. I'll update this to remove "most of".

@nex3 nex3 merged commit 103cb19 into main Sep 21, 2022
@nex3 nex3 deleted the floating-point branch September 21, 2022 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement floating-point numbers
3 participants