public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/42184]  New: Same literal behaves differently as a double than as a long double
@ 2009-11-26 16:06 warp at iki dot fi
  2009-11-26 17:13 ` [Bug c/42184] " kargl at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: warp at iki dot fi @ 2009-11-26 16:06 UTC (permalink / raw)
  To: gcc-bugs

One would assume that the following program prints the same number four times,
but instead "1 0 1 0" is printed. I compiled it with options "-std=c99 -lm".

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
    long double value1 = 1.6646342e21;
    long double value2 = 1.6646342e21L;
    long double value3 = strtod("1.6646342e21", NULL);
    long double value4 = strtold("1.6646342e21", NULL);
    long double divisor = 1.25L;

    printf("%Lg %Lg %Lg %Lg\n",
           fmodl(value1, divisor), fmodl(value2, divisor),
           fmodl(value3, divisor), fmodl(value4, divisor));

    return 1;
}


-- 
           Summary: Same literal behaves differently as a double than as a
                    long double
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: warp at iki dot fi
  GCC host triplet: i586-suse-linux
GCC target triplet: i586-suse-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42184


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/42184] Same literal behaves differently as a double than as a long double
  2009-11-26 16:06 [Bug c/42184] New: Same literal behaves differently as a double than as a long double warp at iki dot fi
@ 2009-11-26 17:13 ` kargl at gcc dot gnu dot org
  2009-11-26 21:12 ` pinskia at gcc dot gnu dot org
  2009-11-26 21:15 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: kargl at gcc dot gnu dot org @ 2009-11-26 17:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from kargl at gcc dot gnu dot org  2009-11-26 17:13 -------
I think that you may be looking at a library issue
and the conversion of a decimal string to binary.

Add
    printf("%La\n%La\n%La\n%La\n", value1, value2, value3, value4);

to your program yields
REMOVE:kargl[209] ./z
0x1.68f5c2c528fa3p+70
0x1.68f5c2c528fa3p+70
0x1.68f5c2c528fa3p+70
0x1.68f5c2c528fa36p+70
1 1 1 0

on FreeBSD.  If I replace 1.6646342e21 everywhere in your program
with 0x1.68f5c2c528fa3p+70, I get the result you expect, ie.,

REMOVE:kargl[212] ./z
0x1.68f5c2c528fa3p+70
0x1.68f5c2c528fa3p+70
0x1.68f5c2c528fa3p+70
0x1.68f5c2c528fa3p+70
1 1 1 1


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42184


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/42184] Same literal behaves differently as a double than as a long double
  2009-11-26 16:06 [Bug c/42184] New: Same literal behaves differently as a double than as a long double warp at iki dot fi
  2009-11-26 17:13 ` [Bug c/42184] " kargl at gcc dot gnu dot org
@ 2009-11-26 21:12 ` pinskia at gcc dot gnu dot org
  2009-11-26 21:15 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-11-26 21:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2009-11-26 21:11 -------
Well FreeBSD has slightly different default x87 precision setting .


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42184


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/42184] Same literal behaves differently as a double than as a long double
  2009-11-26 16:06 [Bug c/42184] New: Same literal behaves differently as a double than as a long double warp at iki dot fi
  2009-11-26 17:13 ` [Bug c/42184] " kargl at gcc dot gnu dot org
  2009-11-26 21:12 ` pinskia at gcc dot gnu dot org
@ 2009-11-26 21:15 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-11-26 21:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2009-11-26 21:15 -------
1.6646342e21 will produce a double and then that is extended into long double.
On the other hand 1.6646342e21L is a long double so it is parsed what you
expect into a long double.

1 0 1 0 is the correct value for x87 (80bit long double).


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42184


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-11-26 21:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-26 16:06 [Bug c/42184] New: Same literal behaves differently as a double than as a long double warp at iki dot fi
2009-11-26 17:13 ` [Bug c/42184] " kargl at gcc dot gnu dot org
2009-11-26 21:12 ` pinskia at gcc dot gnu dot org
2009-11-26 21:15 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).