stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

feat: add `constants/float32/max-safe-nth-fibonacci`

Open gunjjoshi opened this issue 1 year ago • 0 comments

Description

What is the purpose of this pull request?

This pull request:

Related Issues

Does this pull request have any related issues?

This pull request:

  • resolves a part of #649.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

As the max-safe-integer that can be stored in single-precision is 16777215, I chose the maximum possible fibonacci number that can be stored in single-precision to be just below this, which turns out to be 14930352. The next value after that is 24157817 , which is greater than the max-safe-integer.

Also checked it in REPL:

In [11]: float64ToFloat32(24157817)
Out[11]: 24157816

In [12]: float64ToFloat32(14930352)
Out[12]: 14930352

We do not have any precision loss for 14930352, but we do have loss for the next value, i.e., 24157817.

Hence, I chose 36 as the max-safe n.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

gunjjoshi avatar Aug 26 '24 14:08 gunjjoshi