Thread: Is increased precision of intermediate results of floating-point computations legal?

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    1

    Is increased precision of intermediate results of floating-point computations legal?

    Is it legal in standard C++ to treat the intermediate result of a computation as having a greater precision that the source types?

    e.g.
    float f, g, h, x;

    x = f + g + h; // compute f + g to a higher precision than float, then add to h, and finally round to float precision

    If so, is this explicitly stated in the C++ standard? If so, where?

    Thanks.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    It is legal, x86 does it when using x87 computations.
    Quote Originally Posted by 5/10
    The values of the floating operands and the results of floating expressions may be represented in greater precision and range than that required by the type; the types are not changed thereby.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

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. Floating point numbers
    By bulsquare in forum C Programming
    Replies: 2
    Last Post: 04-10-2002, 04:44 AM
  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