Thread: FPN math

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,734
    Also now that I've looked at it a bit more you're version relies on integers bigger than a float, as you may have guessed I will be attempting long doubles later so I'd like to use a version that does not rely on larger integers because that opens up the problem of what to do when there is no such integers, while I can program array type integers I still struggle with the division part which would be essential at the top of your function, I would also need to program a log10 etc variant for those array integers, all that still excludes the possibility of not enough memory anyway.

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by awsdert View Post
    Also now that I've looked at it a bit more you're version relies on integers bigger than a float, as you may have guessed I will be attempting long doubles later so I'd like to use a version that does not rely on larger integers because that opens up the problem of what to do when there is no such integers, while I can program array type integers I still struggle with the division part which would be essential at the top of your function, I would also need to program a log10 etc variant for those array integers, all that still excludes the possibility of not enough memory anyway.
    Take a look at strtod() implementation from glibc... it uses multiple precision (MP) arithmetic. So you need integers with precision greater than the targeted floating point type. You only need integers to hold 2 times the precision of integer type (which is always bigger then the precision of the floating point type). This could be worse for convertions from char to "float", for example, where the expoent is between -126 and 126 (for normalized floats) - perhaps you'll need a MP with 256 bits (to be safe), to do those shifts. But it's not a big deal in terms of memory usage.

    As you've seen, log10 and pow10 is not a big deal to implement...

    With my test, if you are using GCC or CLANG, you can use __int128 type for long doubles.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ and Math
    By darren78 in forum C++ Programming
    Replies: 2
    Last Post: 07-08-2010, 09:19 AM
  2. hex math
    By kroiz in forum C Programming
    Replies: 25
    Last Post: 01-20-2009, 03:46 PM
  3. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 03:14 AM
  4. math.h
    By sweets in forum C++ Programming
    Replies: 2
    Last Post: 05-05-2003, 01:27 PM
  5. Math Help
    By CAP in forum C Programming
    Replies: 2
    Last Post: 08-19-2002, 12:03 AM

Tags for this Thread