dart_numerics icon indicating copy to clipboard operation
dart_numerics copied to clipboard

magnitude(1000.0) should be '3', not '2'

Open dokinkon opened this issue 3 years ago • 3 comments

print(magnitude(1000.0);

output is 2

This should be dart double precision issue.

How can we solve this?

Thanks

dokinkon avatar Mar 03 '21 05:03 dokinkon

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:

  1. Reimplement log10 like a low-level C-implementation. It's a bit tricky and result will be not such fast.
  2. 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?

zlumyo avatar Mar 10 '21 14:03 zlumyo

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.

zlumyo avatar Mar 10 '21 15:03 zlumyo

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.

dokinkon avatar Mar 11 '21 08:03 dokinkon