# Thread: Unlimited length floating point calculator

1. Originally Posted by gcn_zelda
I wish I knew what a modulus is.
I sense your sarcasm, but, as you can tell from Zach's honesty, for some people there exists some ambiguity, or even an extreme lack of clarity. So, let's not be so condescending here, huh, ganon? Word.

2. No, I'm serious. I don't know what a modulus is :P

3. When in doubt, MathWorld!

4. Maybe I'll just wait 'til Calculus or whenever we learn about those thingies.

5. do you ever program. You need modulus in a lot of cases.

6. gcn_zelda:
To calculate 10.2 % .5 you could think of is as repeatedly adding/subtracting 0.5 from 10.2 until to recive a value within 0-0.5.

To calculate x % y, add or subtract y from x until you get a value in the interval [0,y[.

Question:
Why does (pi)! equal approx. 7.68 but
1.3! = 1
Are you using the gamma function or not?

EDIT: Matlab says that gamma(pi + 1) = (pi)! ~= 7.1881
1.3! ~= 1.1667
or
1.3! = 1 if you truncate

7. Bug: When calulating something that takes more than 1 second, you need to report it as such or just change it. I did Pi! and it took 7.xxx seconds, but it says 7.xxx msecs.

Other than that, good job. I didn't dig too hard, but it seems fairly solid.

8. Originally Posted by 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'd say it isn't possible to use "mod 0". It doesn't make any sense.
The calculator answers, somewhat cryptically, 5 % 0 = 00

9. It's a perfectly legal algebraic definition. The element 0 generates an ideal [called (0)] which consists of the element 0 alone. So, you can take the modulus with respect to it. You just need the cosets x+(0) and y+(0) to be identical, which only happens when x=y. See my earlier post that goes into this in more detail.

10. Originally Posted by Sang-drax
Question:
Why does (pi)! equal approx. 7.68 but
1.3! = 1
Are you using the gamma function or not?

EDIT: Matlab says that gamma(pi + 1) = (pi)! ~= 7.1881
1.3! ~= 1.1667
or
1.3! = 1 if you truncate
Pardon my ignorance, but I am unfamiliar with the "gamma function." Thank you for pointing out the mistake. The way I am now calculating factorial (and the way I should have been) is just the standard [n * (n - 1) * (n - 2) * ...]. So, using your example, 1.3! = 1.3 * 0.3 = 0.39. Before I was thinking in terms of integers and stopping at 1 instead of zero. What exactly is "the gamma function" and how does it yield 1.3! = 1.1667? Thanks for the info (the horse's mouth is great, but please don't point me at google).

Bug: When calulating something that takes more than 1 second, you need to report it as such or just change it. I did Pi! and it took 7.xxx seconds, but it says 7.xxx msecs.
Thanks for reporting. Actually it doesn't matter if it is over a second, the result is always in seconds, not milliseconds. It's fixed now. Out of curiosity, what are your specs? I just ran it on this machine (Centrino 1.5Ghz) and it took just over 10 seconds.

In doing more testing of my own I see that I am up against a foe that may conquer me and my measly HugeFloat class. Calculating a number to a floating point power means deadly problems. Currently my exponent function just treats the power like an integer because otherwise I am screwed since things to decimal powers mean strange things. It's possible that it will be a root (e.g., 1 ^ 0.5 = 1 ^ 1/2 = sqrt(1) = 1.4142135623730950488016887242097). If not, what exactly does a power to a floating point value mean? Should I just stick to treating it like an integer always? Should I always check if the exponent can legally be interpreted as a root? I don't know if I'm up for the challenge at this point... Stick a fork in me, I'm done.
[/edit]

11. Bah! You know you can't avoid a link to Google. Of course, you can have one to Not Google too.

12. >>If not, what exactly does a power to a floating point value mean?<<

If you convert the floating point to a fraction, then x^(y/z) is equal to z'th root of (x^y). For example 4^(2/3) is cube root of 4^2. So 4^(3.16529) is (4^3)*(4^(16529/100000)) which is 64 times the the 100000th root of 4^16529.

Not sure exactly how to do a non repeating infinite float though, such as 4^(pi).

13. Originally Posted by LuckY
Pardon my ignorance, but I am unfamiliar with the "gamma function."
The gamma function is defined as following:

G(x) = integral(0,inf) ( t^(x-1) * e^(-t) * dt )

Partial integration shows that G(x+1) = (x+1) * G(x). This combined with G(1) = 1 shows that the gamma function equals the factorial function for integers. The gamma function is a useful generalization of the factorial in some cases.

Originally Posted by LuckY
Calculating a number to a floating point power means deadly problems. [...] If not, what exactly does a power to a floating point value mean? Should I just stick to treating it like an integer always? Should I always check if the exponent can legally be interpreted as a root? I don't know if I'm up for the challenge at this point...
Originally Posted by PJ
Not sure exactly how to do a non repeating infinite float though, such as 4^(pi).
Calculating a real number to the power of a rational number is well-defined. We can use this to define a real number to the power of an irrational:

a^b where a,b € R is defined as following:

lim{p/q -> b} a^(p/q)

i.e. b is approximated with a rational number which gets closer and closer to the actual real number.

Note that this means that raising a negative number to an irrational number is undefined. There's no way of determining the sign of the result.

This is not easy to implement, I can imagine.
I've only done a BigInt class, which is alot easier.

14. Originally Posted by LuckY
Thanks for reporting. Actually it doesn't matter if it is over a second, the result is always in seconds, not milliseconds. It's fixed now. Out of curiosity, what are your specs? I just ran it on this machine (Centrino 1.5Ghz) and it took just over 10 seconds.
2.8 GHz P IV with 512 RAM

15. Okay a much better operating version is available to anyone who is at all interested in using it or bug-running it. You can get it at http://www.geocities.com/lucky760/hugecalc. I made it dual-threaded so that the damn thing doesn't hang up while running long calculations. Also if it's taking too long for your liking you can just hit ESC or click the X to cancel the current computation. In addition to that I added tool tips to tell what things do and what their keyboard equivalents are. That's the other (and best) thing; you can enter values with your keyboard instead of having to mouse click every number. Finally you can cut/copy/paste stuff using CTRL+Z||C||V and SHIFT+INSERT||DELETE.