Thread: Unlimited length floating point calculator

  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    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.

    [edit]
    Removed previous attachment. See below for a revised version.
    [/edit]
    Last edited by LuckY; 11-29-2004 at 06:34 PM.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    <pedantic>Your title is misleading. There is no such thing has unlimited in computers. Eventually you will run out of memory</pedantic>

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Bah! How can you dispute a claim like that Thantos? Now... give me all the digits of pi.

    I'll look at it later. I'm curious what the result of the operator discussion was.
    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. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    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?
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    10.2 % 0.5?
    That operation doesn't completely make sense from an algebraic standpoint.
    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.

  6. #6
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    yes, modulus of non-integer values I thought was undefined?
    there used to be something here, but not anymore

  7. #7
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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
    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.

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Well there is a fmod() so their floating number class should handle it.

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

    [edit]
    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]
    Last edited by LuckY; 11-29-2004 at 07:04 PM.

  10. #10
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Whoaa.. That floating point mod is strange.
    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.

  11. #11
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Why is the floating point mod strange? Hmm..

  12. #12
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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.
    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.

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

  14. #14
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    I wish I knew what a modulus is.

  15. #15
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    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.
    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.

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, 07:11 PM
  2. checking for floating point number
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 08: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, 12:00 PM