Unlimited length floating point calculator

This is a discussion on Unlimited length floating point calculator within the A Brief History of Cprogramming.com forums, part of the Community Boards category; Originally Posted by gcn_zelda I wish I knew what a modulus is. I sense your sarcasm, but, as you can ...

  1. #16
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Quote 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. #17
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    No, I'm serious. I don't know what a modulus is :P

  3. #18
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    When in doubt, MathWorld!
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #19
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Maybe I'll just wait 'til Calculus or whenever we learn about those thingies.

  5. #20
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    do you ever program. You need modulus in a lot of cases.

  6. #21
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    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
    Last edited by Sang-drax; 11-30-2004 at 10:46 AM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  7. #22
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    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. #23
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote 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
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  9. #24
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  10. #25
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Quote 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.

    [edit]
    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]
    Last edited by LuckY; 12-01-2004 at 12:05 AM.

  11. #26
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Bah! You know you can't avoid a link to Google. Of course, you can have one to Not Google too.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  12. #27
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    >>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. #28
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote 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.


    Quote 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...
    Quote 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.
    Last edited by Sang-drax; 12-01-2004 at 07:17 AM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  14. #29
    5|-|1+|-|34|) ober's Avatar
    Join Date
    Aug 2001
    Posts
    4,429
    Quote 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. #30
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    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.

    Thanks for the help you-all.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. floating point number comparison
    By lehe in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2009, 08:11 PM
  2. checking for floating point number
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 09:14 PM
  3. Floating point exceptions
    By Boris in forum C++ Programming
    Replies: 8
    Last Post: 11-19-2001, 08:32 AM
  4. Floating point faster than fixed-point
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-08-2001, 11:34 PM
  5. Replies: 2
    Last Post: 09-10-2001, 01:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21