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

RDART-866: kn/decimal128 web support #1713

Merged
merged 8 commits into from
Jun 7, 2024
Merged

Conversation

nielsenko
Copy link
Contributor

@nielsenko nielsenko commented Jun 6, 2024

As part addressing #1374 in it was found that not allowing Decimal128 fields 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:

  • -0 < 0,
  • NaN != NaN,
  • 1 / 0 = Inf, etc.

Currently anything involving Decimal128.nan, Decimal128.infinity, and Decimal128.negativeInfinity will throw on web, including Decimal128.isNaN.

Also, be warned that this class is incredible slow compared to the native implementation, especially division.

@cla-bot cla-bot bot added the cla: yes label Jun 6, 2024
@nielsenko nielsenko changed the base branch from main to kn/minimal-web-support June 6, 2024 17:36
@nielsenko nielsenko requested a review from nirinchev June 6, 2024 17:50
@nielsenko nielsenko force-pushed the kn/minimal-web-support branch from 4d9f2ce to 1e8e180 Compare June 6, 2024 18:07
Base automatically changed from kn/minimal-web-support to main June 6, 2024 20:58
@nielsenko nielsenko force-pushed the kn/decimal128-web-support branch from bdc06b8 to 8ca922b Compare June 6, 2024 21:03
Copy link

coveralls-official bot commented Jun 6, 2024

Pull Request Test Coverage Report for Build 9407798276

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 86.797%

Totals Coverage Status
Change from base Build 9407730144: 0.0%
Covered Lines: 5943
Relevant Lines: 6847

💛 - Coveralls


/// Converts a `double` into a [Decimal128].
factory Decimal128.fromDouble(double value) => webNotSupported();
factory Decimal128.fromDouble(double value) {
Copy link
Member

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())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Done.

Comment on lines +116 to +98
final sign = _value.compareTo(other._value);
if (sign < 0) return -1;
if (sign > 0) return 1;
return 0;
Copy link
Member

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?

Copy link
Contributor Author

@nielsenko nielsenko Jun 7, 2024

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';
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Fixed.

@nielsenko nielsenko force-pushed the kn/decimal128-web-support branch from 8ca922b to 8dcc430 Compare June 7, 2024 08:19
Copy link

coveralls-official bot commented Jun 7, 2024

Pull Request Test Coverage Report for Build 9413918326

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 86.797%

Totals Coverage Status
Change from base Build 9413903645: 0.0%
Covered Lines: 5943
Relevant Lines: 6847

💛 - Coveralls

@nielsenko nielsenko force-pushed the kn/decimal128-web-support branch from 8dcc430 to e5d73af Compare June 7, 2024 08:59
Copy link

coveralls-official bot commented Jun 7, 2024

Pull Request Test Coverage Report for Build 9414419493

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 86.797%

Totals Coverage Status
Change from base Build 9414399757: 0.0%
Covered Lines: 5943
Relevant Lines: 6847

💛 - Coveralls

@nielsenko nielsenko force-pushed the kn/decimal128-web-support branch from e5d73af to 04cb086 Compare June 7, 2024 09:36
@nielsenko nielsenko marked this pull request as ready for review June 7, 2024 09:43
@nielsenko nielsenko requested a review from nirinchev June 7, 2024 09:46
Copy link

coveralls-official bot commented Jun 7, 2024

Pull Request Test Coverage Report for Build 9415009835

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 86.797%

Totals Coverage Status
Change from base Build 9414399757: 0.0%
Covered Lines: 5943
Relevant Lines: 6847

💛 - Coveralls

@nielsenko nielsenko changed the title kn/decimal128 web support RDART-866: kn/decimal128 web support Jun 7, 2024
@nielsenko nielsenko merged commit 889e434 into main Jun 7, 2024
59 of 63 checks passed
@nielsenko nielsenko deleted the kn/decimal128-web-support branch June 7, 2024 12:25
nirinchev added a commit that referenced this pull request Jun 12, 2024
* 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
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants