News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Very High Precision Floating-Point

Started by Neo, August 09, 2009, 02:14:36 AM

Previous topic - Next topic

Neo

Weird question: anyone know of any simple bits of code out there for doing high-precision floating-point arithmetic, like let's say with 512 to 2048 mantissa bits?  I just need addition, subtraction, multiplication, and division.  It's not too hard to write my own, I'm just asking in case someone's already got this kind of thing done already.

It's a long story as to why I'd like to use such high-precision arithmetic, but in a nutshell, I've got an "unknown" function that I can compute, but for which I'm trying to find about 20 terms of its Taylor series.  It wouldn't be hard to do this if the function was differentiable, but it's a function only defined on reciprocals of integers, so I have to get very precise data points and do a least squares analysis to solve for the Taylor series.  Once I've got its Taylor series, I'll try to see if there's a simple, closed-form of the function.

dedndave

#1
i doubt you will find code like that - it's a bit of an overkill
part of the reason is, there is no way to collect data points with such high precision
in fact, you will have a hard time getting data points with 64 bits of precision
what you probably really need is more range, not precision

but, it can be written, of course
i think you could use the FPU and extend the precision
512 bits would be 8 X the precision of 80-bit extended reals
addition and subtraction would be relatively simple
multiplication, a bit more difficult
and division will get a bit messy, especially if the divisor has to be 512 bits wide, as well

raymond

Quotewith 512 to 2048 mantissa bits

That's equivalent to a precision of around 150 to 600 significant decimal digits. My curiosity is certainly aroused to become aware of an "unknown" function which needs such high precision.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

drizz

The truth cannot be learned ... it can only be recognized.

ecube

if anyone could do it in ASM raymond could, hes the FPU guru around here.

MichaelW

eschew obfuscation

Neo

Quote from: dedndave on August 09, 2009, 03:43:44 AM
in fact, you will have a hard time getting data points with 64 bits of precision
what you probably really need is more range, not precision
In this case, I can compute the data points to arbitrary precision.  They're not measured values, but rather computed from a function on integers.  Edit: If the integer is n, I need around 2n bits per floating-point number to accurately calculate the value of the function, and I definitely need a lot of bits to calculate a degree-20 least squares analysis, since it's quite unstable beyond degree-4.

Quotei think you could use the FPU and extend the precision
512 bits would be 8 X the precision of 80-bit extended reals
addition and subtraction would be relatively simple
multiplication, a bit more difficult
and division will get a bit messy, especially if the divisor has to be 512 bits wide, as well
I'm thinking it'd be easier to use integer math to do it, 'cause if there's one bit in the middle that gets rounded off, the whole number's toast.

QuoteThat's equivalent to a precision of around 150 to 600 significant decimal digits. My curiosity is certainly aroused to become aware of an "unknown" function which needs such high precision.
Well, it's unknown in that I know one way of computing it to arbitrary precision without a closed form, but there may be a closed form, which could have very significant implications.  If I get the Taylor series down and I can't find a nice closed form myself, I'll probably offer a significant reward for finding a closed form, so I don't want to bias people's ideas by telling them where the function comes from until they're close.  I can tell you that the inputs are all reciprocals of even integers, so they're in the range (0,0.5], that I need to use pi to many bits of precision, and that the value approaches 1 as the input approaches 0.

The reason I think that there is a closed form (or at least a much simpler form) is that the 4 terms I have so far all have coefficients that are reciprocals of integers, which would be very unlikely for a completely general function.

Sorry for being so mysterious.  :8)

dedndave

no prob - it sounds like a fun puzzle - lol
from my experience, it always helps to graph the function
somehow, my brain finds it easier to see a pattern or shape i recognize from some other adventure

chrisw

Did you think about approximating the <unknown> function by a polynome instead of a taylor series? Or a rational approximation with polynomes?
Maybe you won't need a degree of 20 here. I made good experience using a Remez approximation of functions in a limited domain with sufficient precision ...


regards,
Christian

Neo

Quote from: chrisw on August 10, 2009, 12:20:16 PM
Did you think about approximating the <unknown> function by a polynome instead of a taylor series? Or a rational approximation with polynomes?
Maybe you won't need a degree of 20 here. I made good experience using a Remez approximation of functions in a limited domain with sufficient precision ...
C'est vrai, mais l'objectif final n'est pas d'approximer la fonction.  Je veux trouver une expression finie et exacte pour la fonction.  La série de Taylor est seulement pour assister avec la cherche.  Donc, s'il y a une expression finie qui est rationelle ou exponentielle avec des polynômes, ce serait très bon.

Pardon my French.  Yes, I wrote it in French just so I could say that  :lol

dedndave

not fair - you gave the French guy hints - lol

raymond

QuoteI can tell you that the inputs are all reciprocals of even integers, so they're in the range (0,0.5], that I need to use pi to many bits of precision, and that the value approaches 1 as the input approaches 0.

Sound like a problem in Number Theory. I know a few persons at Project Euler who are geniuses in that domain. Let me know if you ever need help.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

dedndave

QuoteProject Euler
that rings a bell
where have i heard that before ?

raymond

When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

dedndave

lol Ray - i googled it of course
i remember that site - they have some pretty obscure math puzzles - lol