dart_numerics
dart_numerics copied to clipboard
magnitude(1000.0) should be '3', not '2'
print(magnitude(1000.0);
output is 2
This should be dart double precision issue.
How can we solve this?
Thanks
Hello!
Yes, it's a double precision issue. To be more precise the underlying implementation uses inaccurate version of log10 function. Unfortunately, dart:math doesn't have its own log10 alongside log (which uses low-level C-implementation).
I think there are 2 options:
- Reimplement log10 like a low-level C-implementation. It's a bit tricky and result will be not such fast.
- Use FFI to call real C-implementation. But then the code will become platform-dependent.
Which option is better? Well, I think the first one. But maybe I'm wrong. What it is your opinion?
Oh, almost forgot it, but there is also one another option: introduce log10 function to dart:math 😃 And according to this issue they are planning it.
Thanks for your effort. I prefer pure dart solution personally. But you're the guy who made final decision. And I'm urgent on this. If dark-sdk could provide log10 function, this is perfect solution. Thanks.