Project

General

Profile

Actions

Bug #14935

open

float/double support is broken in gcc-4.9+ with -m32 -std=c99

Added by Marcel Telka about 1 year ago. Updated 4 months ago.

Status:
New
Priority:
Normal
Assignee:
Category:
OI-Userland
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:

Description

$ cat <<"EOF" > test.c
#include <stdio.h>

int
main(void)
{
        float f = 3.14159f;
        if (f != 3.14159f)
                printf("\tfloat BAD\n");

        double d = 30.03;
        if (d != 30.03)
                printf("\tdouble BAD\n");

        return 0;
}
EOF
$ for gcc in /usr/gcc/* ; do
        v=$(basename $gcc)
        for b in 32 64 ; do
                for std in "" -std=c99 -std=gnu99 ; do
                        /usr/gcc/$v/bin/gcc -Wall -m$b $std -o test.out test.c
                        echo "gcc-$v: -m$b $std" 
                        ./test.out
                        rm -f test.out
                done
        done
done
gcc-10: -m32 
gcc-10: -m32 -std=c99
        float BAD
        double BAD
gcc-10: -m32 -std=gnu99
gcc-10: -m64 
gcc-10: -m64 -std=c99
gcc-10: -m64 -std=gnu99
gcc-11: -m32 
gcc-11: -m32 -std=c99
        float BAD
        double BAD
gcc-11: -m32 -std=gnu99
gcc-11: -m64 
gcc-11: -m64 -std=c99
gcc-11: -m64 -std=gnu99
gcc-3.4: -m32 
gcc-3.4: -m32 -std=c99
gcc-3.4: -m32 -std=gnu99
gcc-3.4: -m64 
gcc-3.4: -m64 -std=c99
gcc-3.4: -m64 -std=gnu99
gcc-4.9: -m32 
gcc-4.9: -m32 -std=c99
        float BAD
        double BAD
gcc-4.9: -m32 -std=gnu99
gcc-4.9: -m64 
gcc-4.9: -m64 -std=c99
gcc-4.9: -m64 -std=gnu99
gcc-7: -m32 
gcc-7: -m32 -std=c99
        float BAD
        double BAD
gcc-7: -m32 -std=gnu99
gcc-7: -m64 
gcc-7: -m64 -std=c99
gcc-7: -m64 -std=gnu99
$
Actions #1

Updated by Marcel Telka about 1 year ago

  • Subject changed from float support is broken in gcc-7 with -std=c99 to float/double support is broken in gcc-7 with -std=c99
  • Description updated (diff)
Actions #2

Updated by Marcel Telka about 1 year ago

  • Subject changed from float/double support is broken in gcc-7 with -std=c99 to float/double support is broken in gcc-4.9+ with -m32 -std=c99
  • Description updated (diff)
Actions #3

Updated by Marcel Telka about 1 year ago

  • Description updated (diff)
Actions #4

Updated by Andreas Wacknitz about 1 year ago

I have checked gcc-7, -9, and -10 on omnios-r151038. They have the same problem.

Actions #5

Updated by Dmitry Kozhinov 4 months ago

Marcel Telka wrote:

        float f = 3.14159f;
        if (f != 3.14159f)
                printf("\tfloat BAD\n");

You should never compare floats and doubles using == and != operators, because exact equality is not guaranteed. As far as I understand, this is due to some unpredictable rounding in representation of float and double values in CPU.

I suggest closing this issue.

Actions

Also available in: Atom PDF