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

Int is not a true 64 bit - other type needed #2

Closed
vemla-solutions opened this issue Nov 20, 2021 · 2 comments
Closed

Int is not a true 64 bit - other type needed #2

vemla-solutions opened this issue Nov 20, 2021 · 2 comments

Comments

@vemla-solutions
Copy link

Hello

The four seed parameters defined for Xoshiro256ss are int each.
However, in dart the int type is only 2^63-1 max value, because 1 bit is used for defining the sign (https://stackoverflow.com/a/53591126/346488).
Which means int is not a proper type to use as an input, as it is not possible to pass each part as a true 64-bit integer.

E.g. I have an issue passing one as:
int.parse('f78207dec08eba34', radix:16)
It returns an error:
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FormatException: Positive input exceeds the limit of integer

It looks like the right approach would be to use BigInt as input parameters type and then check inside that each parameter is within 64 bits.

Could you please check on this?
Thank you!

@rtmigo
Copy link
Owner

rtmigo commented Nov 21, 2021

Although the positive int values in Dart VM do not exceed 2^63-1, these variables are still true 64-bit integers.

If it were a C language, we would clarify that we are talking about 64-bit signed, not 64-bit unsigned. But these are not two fundamentally different things. In many cases, they are interchangeable and almost identical.

In a particular case, to pass a large unsigned number f78207dec08eba34 as a seed, you just need to use its signed counterpart -87df8213f7145cc. This number will fit into a regular int in Dart.

import 'package:fixnum/fixnum.dart';

void main() {
  // interpreting a large number constant as a regular int (aka 64-bit signed)
  int seed = Int64.parseHex('f78207dec08eba34').toInt();
  ...
}

@vemla-solutions
Copy link
Author

Thanks, I've seen this fixnum library, but didn't realize that it actually can be used to convert to a standard "int" type instead of using their Int64.
It works fine, the issue can be closed.
Thank you for your help!

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

No branches or pull requests

2 participants