c++/7923: g++ - inline cast of double to long returns incorrect value

Ian.Nowland@silverbrookresearch.com Ian.Nowland@silverbrookresearch.com
Sun Sep 15 23:56:00 GMT 2002


>Number:         7923
>Category:       c++
>Synopsis:       g++ - inline cast of double to long returns incorrect value
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Sep 15 21:16:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Ian.Nowland@silverbrookresearch.com
>Release:        gcc 3.2 20020818, gcc 2.95
>Organization:
>Environment:
Cygwin and SuSe Linux 7.2 on Intel
>Description:
In both of these environments the following code should print the same value all three times. However the third value is incorrectly printed as 256.

#include <math.h>
#include <iostream>

int main()
{
    double maxLinearValue = 65535.0;
    double ian = maxLinearValue * pow(double(1.0/ 255.0), 1.0);
    long correctLongValue = long(ian);
    long incorrectLongValue = long(maxLinearValue * pow(1.0/ 255.0, 1.0));
    std::cout << "double: " << ian << std::endl;
    std::cout << "correct: " << correctLongValue << std::endl;
    std::cout << "incorrect: " << incorrectLongValue << std::endl;

    return 0;
}
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list