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

Unexpected return value #37

Closed
gagmeng opened this issue Jan 24, 2024 · 6 comments
Closed

Unexpected return value #37

gagmeng opened this issue Jan 24, 2024 · 6 comments

Comments

@gagmeng
Copy link

gagmeng commented Jan 24, 2024

QQ截图20240124164953

_2024_01_24_18_26_41_464.mp4

Numara does not support 64-bit data types; is that correct?

@bornova
Copy link
Owner

bornova commented Jan 24, 2024

Hi @gagmeng,
Yes, I believe 64-bit data puts the answer out of range of the calculator so it may give unexpected results. However, converting the decimal value to a BigNumber first would fix the problem. You can try:

format(bignumber('-830'), {notation: "hex", wordSize: 64})  // 0xfffffffffffffcc2i64

Similar issue with the second part of your questions. Numbers greater than 15 significant digits would need to be converted to bignumber first. Here is an example:

hex(bignumber('18446744073709550') + 2931)  // 0x4189374bc6b361
hex(bignumber('18446744073709551') + 2931)  // 0x4189374bc6b362
hex(bignumber('18446744073709552') + 2931)  // 0x4189374bc6b363
hex(bignumber('18446744073709553') + 2931)  // 0x4189374bc6b364

On that note, I did find that using a number instead of string value in bignumber function gives incorrect result:

hex(bignumber(18446744073709551) + 2931)  // 0x4189374bc6b361
hex(bignumber('18446744073709551') + 2931)  // 0x4189374bc6b362

This may be a bug with Math.js and I will report it there.

Thank you!

@bornova
Copy link
Owner

bornova commented Jan 24, 2024

On that note, I did find that using a number instead of string value in bignumber function gives incorrect result:

hex(bignumber(18446744073709551) + 2931)  // 0x4189374bc6b361
hex(bignumber('18446744073709551') + 2931)  // 0x4189374bc6b362

This may be a bug with Math.js and I will report it there.

I posted the question here and looks like it has to do with the rounding errors when it comes to javascript handling large numbers.

@gagmeng
Copy link
Author

gagmeng commented Jan 25, 2024

QQ截图20240125105028

@bornova
Copy link
Owner

bornova commented Jan 25, 2024

Hi @gagmeng,
Using bignumbers has its limitations unfortunately 😞 but I am not getting the same results on my end with default settings:

image

Have you changed any settings? and can you please the share the Error message.

@gagmeng
Copy link
Author

gagmeng commented Jan 26, 2024

QQ截图20240126084343
QQ截图20240126085823
The settings are below:
QQ截图20240126084519

Best regards,
gagmeng

@bornova
Copy link
Owner

bornova commented Feb 4, 2024

Hi @gagmeng,
Sorry I was away for a few days. Looks like you are the limitation of javascript when it comes to dealing with large numbers unfortunately. 😞 v4.4.3 does have a minor improvement to BigNumber but not sure if it will resolve your issues. Since I rely on Math.js, I wouldn't be able to offer much help on this.

@bornova bornova closed this as completed Mar 26, 2024
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