-
Notifications
You must be signed in to change notification settings - Fork 113
RDART-866: kn/decimal128 web support #1713
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
Conversation
4d9f2ce to
1e8e180
Compare
bdc06b8 to
8ca922b
Compare
Pull Request Test Coverage Report for Build 9407798276Details
💛 - Coveralls |
|
|
||
| /// Converts a `double` into a [Decimal128]. | ||
| factory Decimal128.fromDouble(double value) => webNotSupported(); | ||
| factory Decimal128.fromDouble(double value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we take a shortcut here and do a Decimal.parse(double.toString())?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Done.
| final sign = _value.compareTo(other._value); | ||
| if (sign < 0) return -1; | ||
| if (sign > 0) return 1; | ||
| return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to return sign directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm trying to make as many as the decimal128_test.dart tests pass as possible. The behaviour of double will not just return the value of a - b, hence native.Decimal128 doesn't either, and nor should web.Decimal128.
But you could argue that we are already deviating a lot from the semantics of IEEE 754-2008, and the semantics of double so perhaps it is a mood point.
| import 'package:decimal/decimal.dart'; | ||
| import 'package:rational/rational.dart'; | ||
|
|
||
| import 'package:realm_dart/src/handles/native/convert.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this depend on something in native?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Fixed.
8ca922b to
8dcc430
Compare
Pull Request Test Coverage Report for Build 9413918326Details
💛 - Coveralls |
8dcc430 to
e5d73af
Compare
Pull Request Test Coverage Report for Build 9414419493Details
💛 - Coveralls |
e5d73af to
04cb086
Compare
Pull Request Test Coverage Report for Build 9415009835Details
💛 - Coveralls |
* main: Add vNext Changelog header (#1717) [Release 3.0.0] (#1716) libraryVersion moved to realm_libary.dart (take 2) libraryVersion moved to realm_libary.dart Update CHANGELOG (#1715) Github composite action for setting up flutter on runner (#1710) RDART-866: kn/decimal128 web support (#1713) Reduce expected gain of memEquals for test stability Refresh after awaiting download to stabilize tests RDART-866: Minimal web support (#1699) RDART-1052: Update realm-core to v14.9.0 (#1704) RDART-1020: Fix writeAsync behaviour (#1666) RDART-999: Fix flutter test dlopen (#1623) RDART-1045: Expose setrlimit ios (#1700) RDART-962: Use xcode 15.4 (#1548) RDART-1039: Drop catalyst support. Flutter doesn't support it (#1696) # Conflicts: # packages/realm_dart/src/realm-core
As part addressing #1374 in it was found that not allowing
Decimal128fields on unmanaged realm models when used on the web platform was problematic for one of our users. Hence this PR adds support for that as well.This is not a fully compliant IEEE 754-2008 Decimal128 implementation, as it is just based on the decimal package. Which is based on the rational package, which is again based on the BigInt class.
The issues are mostly in some of the odd corner cases of IEEE 754-2008 floating point values, such as:
Currently anything involving
Decimal128.nan,Decimal128.infinity, andDecimal128.negativeInfinitywill throw on web, includingDecimal128.isNaN.Also, be warned that this class is incredible slow compared to the native implementation, especially division.