Square Root: Digit by Digit Algorithm
|
11-25-2022, 10:59 AM
Post: #5
|
|||
|
|||
RE: Square Root: Digit by Digit Algorithm
(11-25-2022 09:30 AM)brouhaha Wrote: if there's a fixed-length field that specifies the length of the variable-length number, then there is an implementation limit, though it might be bigger than the amount of DRAM in existence. As a playground I recommend to use an online Jupyter-Lab. There mpmath is preinstalled. Code: from mpmath import * The Naïve Way Code: mp.dps = 10 (mpf('1.41421356237'), mpf('0.3465735902791')) Code: mp.dps = 100 (mpf('1.414213562369695864617824554443359375'), mpf('0.3465735902791493572294712066650390625')) First I was surprised but then I noticed: nah, that aren't 100 digits. The Lazy Way Using functions as numbers we can postpone the evaluation. Code: mp.dps = 10 (mpf('1.41421356237'), mpf('0.3465735902791')) Code: mp.dps = 100 (mpf('1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641572735'), mpf('0.3465735902799726547086160607290882840377500671801276270603400047466968109848473578029316634982093437698')) The usage is rather clumsy but could be improved by wrapping these "lazy numbers" in a class. Digits that have been calculated could be cached. Maybe someone already did this? (11-25-2022 09:30 AM)brouhaha Wrote: Egbert said "in current computers numbers can be expressed only to a limited number of digits", implying the possibility of computers in some other era (as opposed to "current") that can express numbers to an unlimited number of digits. I can't even begin to imagine how that could be done. You enter 2 and press the √ button. And then you die before reading all the digits. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)