float equality

dsimcha dsimcha at yahoo.com
Sun Feb 20 20:38:05 PST 2011


On 2/20/2011 11:32 PM, Walter Bright wrote:
> Kevin Bealer wrote:
>> == Quote from Walter Bright (newshound2 at digitalmars.com)'s article
>>> Kevin Bealer wrote:
>>>> You could switch to this:
>>>>
>>>> struct {
>>>> BigInt numerator;
>>>> BigInt denominator;
>>>> };
>>>>
>>>> Bingo -- no compromise.
>>> It cannot represent irrational numbers accurately.
>>
>> True but I did mention this a few lines later.
>
> I guess I'm not seeing the point of representing numbers as ratios. That
> works only if you stick to arithmetic. As soon as you do logs, trig
> functions, roots, pi, etc., you're back to square one.

You, my friend, have obviously never used a computer algebra system (my 
favorite is Maxima) at all seriously.  I'm not saying it's a practical 
solution in the context of this discussion, but it is a possible 
solution in a lot of cases.  Basically, if you can't compute something 
exactly, you do the math symbolically (but programmatically) for as long 
as possible.  You convert to a floating point number only when it's 
explicitly asked for.


More information about the Digitalmars-d mailing list