Skip to content

Fails with big modular expressions #3363

Closed Answered by gwhitney
fcnjd asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  • You …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by fcnjd
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3362 on January 27, 2025 02:36.