-
First, thank you for creating this great library, it helps me a lot in my software I'm currently building and is very easy to use. I don't want to be annoying here, but came across some results which might be misleading here. To Reproduce
As a result, 0 is shown. However, Because of Fermat's little theorem, this is supposed to be 1.
returns -4096, which is obviously not part of the group of numbers modulo 47. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
What's going on here is that these exponential expressions with even medium-sized exponents are producing very large intermediate values that exceed the range in which JavaScript's built-in There are various possible solutions/workarounds that one can use to address this:
The JavaScript
Finally, I will move this to a discussion, since it is not an "issue" with mathjs per se at the moment. (It is the expected behavior given the default use of JavaScript |
Beta Was this translation helpful? Give feedback.
-
Hi @gwhitney , |
Beta Was this translation helpful? Give feedback.
What's going on here is that these exponential expressions with even medium-sized exponents are producing very large intermediate values that exceed the range in which JavaScript's built-in
number
type (IEEE 64-bit floating point numbers) can precisely represent each distinct integer. Hence, the result of e.g.7^46
is a floating point number approximately equal (with 53 bits of accuracy in the mantissa) to seven raised to the 46th power, but considering that representation as a specific integer (which is not really appropriate), it is a different integer which does not have the correct residue mod 47.There are various possible solutions/workarounds that one can use to address this: