Write your own arbitrary-precision JavaScript math library
jrsinclair.com
jrsinclair.com
Here is a Python library that employs continued fractions to this end: [0]. You can pull successive partial quotients of the result from the root node of the dag. Whenever any node needs more precise input to deliver more precise output, it pulls a partial quotient from its argument(s).
Full disclosure: I wrote the original version of the library 13.5 years ago. Here are the slides from my talk about it: [1].
[0] https://github.com/AdamPrzybyla/python-cf
[1] https://marcinciura.files.wordpress.com/2019/10/cf-slides.pd...
I do not see how this can be possible. Wouldn't that amount to prove a lot of hard math theorems (e.g, riemann hypothesis)?
if (x < 1):
may halt, trying to compute x to a higher and higher precision? # Idealistically inclined folks, who would prefer their
# computations to hang rather than to yield a heuristic result,
# can achieve this effect by setting accuracy to a negative
# value. By the
# Gauss-Kuzmin theorem [5, 6], a partial quotient in the
# continued fraction expansion of almost every number exceeds
# 1e+31 with probability log2(1+1e-31) =~= 1e-31/ln(2) =~=
# 1.5e-31.Notice that this result does not say that most numbers have bounded partial quotients. In fact, a classical result in diophantine approximation theory, if I recall correctly, says that the set of numbers whose partial fractions are bounded (called badly aproximable numbers) is of Lebesgue measure zero. Thus, if your system represents real numbers by sequences of bounded partial quotients, then it can only represent a negligible (but uncountable) set of real numbers. A "random" number in [0,1] will certainly have an unbounded sequence of partial quotients (i.e., with probability 1).
https://news.ycombinator.com/item?id=24700705
The Android calculator app. got some nice usability improvements by using a combination of rationals, as described in this story, and recursive (aka constructive or computable) reals.
A previous post on Microsoft's calculator brought my attention to an old package it uses called Ratpack (aka ratpak), another implementation of rationals:
https://news.ycombinator.com/item?id=19321217
It has some nice properties for use in a calculator, but it can be quite slow.
When I come across a library with, shall we say, an exotic numeric representation, it's nice to have a library of mathematical functions included. I see that python-cf indeed includes a solid batch.
A lot of the articles in conjunction with some other resources[1][2][3] are great for diving into functional programming (I've watched and read these many times).
If you do front end development with React, I highly recommend the following two videos[4][5] with Ryan Florence and Micahel Jackson (devs behind react-router and Remix) on the compositional nature of React components and hooks.
The last note I'll add is, once you get into Functional Programming, you start wanting to use `compose` or its counter part, `pipe` everywhere and coding becomes a lot more fun.
I'll put a final plug for one of my own posts on how composition manifests in Javascript/React code[6].
[1] https://jrsinclair.com/articles/2019/elegant-error-handling-...
[2] https://drboolean.gitbooks.io/mostly-adequate-guide-old/cont...
[3] https://www.youtube.com/watch?v=Nrp_LZ-XGsY
[4] https://www.youtube.com/watch?v=nUzLlHFVXx0
[5] https://www.youtube.com/watch?v=1jWS7cCuUXw
[6] https://hackernoon.com/forms-of-composition-in-javascript-an...
In Go each integer type has a maximum value. eg int32 has a max value of 2,147,483,647. You can still perform arbitrary-precision arithmetic in Go but it requires using the math/big library.
https://www.python.org/dev/peps/pep-0237/
This was a nice enhancement with very few drawbacks, but I can see how it wouldn't necessarily be appropriate in Go.
>>> type(1)
<type 'int'>
>>> type(1111111111111111111111111111111111111111111111111111111111111)
<type 'long'>Could we replace the 0 generation code with `'0'.repeat(n)`? Or `Array(n).fill(0).join("")` if old JS engine support is required?
Ive always wondered how libraries like big.js works but man it's just unreadable for beginners trying to understand the math behind it
That really is disappointing. BTW, a Javascript interpreter with proper tail calls is built in to every Mac, but it's not in the path by default: https://stackoverflow.com/a/61740889/5641202
Just FYI if you want to run recursive Javascript from the command line in MacOS.
(= (+ 0.1M 0.2M) 0.3M)
true
Not such a stupid language.> 0.1 + 0.2 == 0.3
True
Decimal numbers are rational number types by default in Raku.