# Unlimited length floating point calculator

Show 80 post(s) from this thread on one page
Page 1 of 3 123 Last
• 11-29-2004
LuckY
Unlimited length floating point calculator
So I've been working on this HugeFloat class for a little while and just wrote a little sloppy calculator to try using it (and found a couple of minor problems). I was just hoping some of you might not mind doing the same. I'd appreciate any comments or suggestions or bug observations.

I was also thinking of making this little app more like Windows calc.exe (allowing keypresses to do things instead of only mouse clicks), but it wasn't cooperating with my efforts and I didn't want to waste time trying to figure it out (specifically trying to catch keypresses and simulate the corresponding button being depressed and released). If you have any tips or ideas in this area, please do let me know.

Thanks for taking the time to look. I'm all ears.

Removed previous attachment. See below for a revised version.
[/edit]
• 11-29-2004
Thantos
<pedantic>Your title is misleading. There is no such thing has unlimited in computers. Eventually you will run out of memory</pedantic>
• 11-29-2004
Zach L.
Bah! How can you dispute a claim like that Thantos? Now... give me all the digits of pi. :D

I'll look at it later. I'm curious what the result of the operator discussion was. :)
• 11-29-2004
Sang-drax
BUG 1: I tried to calculate 10.2 % 0.5 and it crashed.
BUG 2: I tried to calculate 2.4! and it crashed.

How do I calculate a fraction to more digits than the default?
• 11-29-2004
Zach L.
10.2 % 0.5?
That operation doesn't completely make sense from an algebraic standpoint.
• 11-29-2004
yes, modulus of non-integer values I thought was undefined?
• 11-29-2004
Zach L.
Well, mathematically, it is defined, but not very useful. The only two things you can take the modulus of in the rationals, Q (or the reals, R) are Q itself and 0, and
x = x (mod 0) [another way of writing x = x]
x = y (mod Q (or R)) [with a fixed x, this is satisfied by all y in the field]

I suppose you could make some operation to find out the integral number of times that one rational/real goes into another, but there doesn't seem to be anything particularly special about that operation.

Cheers
• 11-29-2004
Thantos
Well there is a fmod() so their floating number class should handle it.
• 11-29-2004
LuckY
Thanks for pointing out the bugs SangDrax. Interestingly (and annoyingly) enough the bug is of the simplest degree (just like the other bugs I found today). It is the simple > and < operators going out of range.

I've attached a revised version that correctly reports 10.2 % .5 = .2 and 2.4! = 3.36

You guys are right as far as I can tell about mod not being all that useful for floating point numbers, but since I was creating a floating point number class I felt it was absolutely necessary for whatever maniacs could find a reason to make good use of it; besides, I needed SangDrax to find something wrong. ;P

Thanks for checking it out. Again, any other bugs or suggestions are greatly appreciated.

I forgot that you wanted to be able to change decimal precision, SangDrax, but just remembered and included it (the library code was there but I was too lazy earlier to add the dialog functionality). Also, it will tell you how long your last calculation took.
[/edit]
• 11-29-2004
Zach L.
Whoaa.. That floating point mod is strange.
• 11-29-2004
LuckY
Why is the floating point mod strange? Hmm..
• 11-29-2004
Zach L.
It just doesn't fit the algebraic definition of modulus, so I don't know what it is doing. I would've expected it to be defined so that 10.2 % .5 = 20 (20 * .5 <= 10.2 < 21 * .5). [I take it fmod does exactly what your code does as well.]
At some point tonight, when I have time, I'm gonna open up that code and figure out what is going on. :)
• 11-29-2004
LuckY
Well, if you think about it it really isn't too strange. If you multiplied both of those operands by 10 it would be 102 % 5 = 2. In all actuality, it is very simply the remainder after a divide, so the result should be < the denominator (0.5). With this in mind, it doesn't seem to weird that the result would be 0.2, right?
Let me know what you come up with.
• 11-29-2004
gcn_zelda
I wish I knew what a modulus is.
• 11-29-2004
Zach L.
That works as a definition. I just wasn't sure what it was.

The one I am used to is as follows. You have a set with an addition operator and a multiplication operators such that there is a multiplicative identity in the set (1*a = a) and an additive identity (0+a=a). Additionally, both operations are commutative and associative, and addition is invertible (a in the set implies -a in the set so a+(-a)=0), but not necessarily so for multiplication. Call the set R.

So, an ideal is a subset p (called an ideal) such that within p, you have 0, and -a for each a in it. Additionally, R*p=p (any element of R times any in p yields one in p). And you take the modulus with respect to the ideal. So, x=y(mod p) means x-y is in p. For the integers, each ideal is generated by a single element (the element and its product with everything else), so you just write the x=y(mod n) where n is the generating integer.

For something that has multiplicative inverses for all of its non-zero elements, like the rationals or reals, then it turns out that the only primes are the one generated by 0 and the field itself (F).
So, x=y(mod 0) is x-y is some multiple of 0 and hence x=y
While x=y(mod F0 is x-y is in F, so the have no special relation to each other (particularly since this was required by the definition of F).

That was a long-winded explanation of why it didn't make sense to me. :) That said, the definition you gave makes much more sense than the one I proposed a post ago.
Show 80 post(s) from this thread on one page
Page 1 of 3 123 Last