Results 1 to 7 of 7

Thread: extended precision math class

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Question extended precision math class

    Does anyone know if there is a custom math class out there that will output extended decimal values as aasci strings of digits?

    For example, sqrtf(2.0) and sqrtl(2.0) both return 1.4142135623730951 but the Windows Calculator displays 1.4142135623730950488016887242097.

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396

    Windows Calculator

    I think that fellow wrote a emulated 128bit floating point unit using integer units of the CPU bcos FPU only support 32bit(float), 64bit(double) and 80bit(long double (borland only)).

    Of course, that also means he wrote all the functions to support it.

    Long time ago, CPUs, without FPU, calculated floats arithmetic with emulated FPU using integer units. This method is very slow.

    Today, all CPUs come with built in FPU.
    Last edited by transcendental; Aug 28th, 2002 at 09:41 PM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    I would be interested in seeing some of this.
    Most of the calculations are done fast enough not to notice anyway.

  4. #4
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Fast?

    It depends on what your app should be doing.

    What a FPU double(64bit) multiplication takes 1 cycle but a 128bit emulated multiplication takes 100 cycles or more(I'm not sure).

    Let me quote an example of emulated 128bit integer addition.

    Bcos the register size is 32bit, to do addition of 128bit, u need to load it 4 times and each time u add, u must take care of any carry from previous addition of 32 bits. U see even 128bit takes several cycles to accomplish the integer addition task

    Now u know __int64 in VC++ is also an emulated type bcos Intel (& compatibles) only support native integer size of max 32bit.

    wey97, someone in Maths forum once mentioned before double should have the precision u need, as the distance from the Sun to Earth can be given in centimetres resolution, using Double type.

  5. #5
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    A proof that VC++ 6 sucks.

    From MSDN,

    Previous 16-bit versions of Microsoft C/C++ and Microsoft Visual C++ supported the long double, 80-bit precision data type. In Win32 programming, however, the long double data type maps to the double, 64-bit precision data type. The Microsoft run-time library provides long double versions of the math functions only for backward compatibility. The long double function prototypes are identical to the prototypes for their double counterparts, except that the long double data type replaces the double data type. The long double versions of these functions should not be used in new code.
    I heard from somebody that Borland C++'s long double is 80bit.

    From MSDN(I couldn't find it now) it also stated it is perfectly alright for long double to be 64bit bcos C++ spec allow it.

  6. #6
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    This is what I posted in my local forum, basically I copied and pasted here. U might be interested to read it. I took float type as example to illustrate my point.

    ===========================================

    What do u mean? Got any sample code to show.

    This is inherent nature of FPU, not the fault of C++.

    Take float for 3.698x10^-3 add to 6.258x10^9

    To a normal programmer, he will nvr forseen such problem. Bcos to him and u, as long as they are within 1.175x10^-38 and 3.4x10^38 of float type, it will be alright.

    Wrong bcos this addition add 2 numbers which are out of range of each other, even though they are within float boundaries.

    Why? bcos float have precision up to (but not limited to) 7 numbers places. The distance between 3.698x10^-3 and 6.258x10^9 is 12 places. so the addition result is still 6.258x10^9 .

    These programming problems are only known to engineers and computer scientists bcos they deal with
    very small and very big numbers. As for solutions to such problem I dunno=P, is u shld be aware of such problems resulting in erroneous computations, especially in Numerical Methods.

    Commercial programmers seldom calculates such extreme values. I had not been in IT course so I dunno if they are at least briefly mentioned to, about this problem.

    Another type of FP have no such 'out of range' problem is fixed point. Bcos for fixed point, the decimal point is fixed. Floating point is not fixed, thus is called floating pt, can represent larger range.

    The range that can be represented by fixed point is much lower. Integer is also known as a type of fixed pt but integer cannot represent fractional parts and fixed pt can. Both decimal points are fixed for sure.:laugh:

    Another problem of FPU is not all numbers can be perfectly represented by Floating Pt.

    ==============The End=====================
    Last edited by transcendental; Aug 29th, 2002 at 06:13 AM.

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by transcendental
    Now u know __int64 in VC++ is also an emulated type bcos Intel (& compatibles) only support native integer size of max 32bit.
    I think MMX provides 64-bit registers, and there might be some of that size on the older Pentiums as well.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width