Bug 53095 - std=gnu99 atof x86
Summary: std=gnu99 atof x86
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.7.0
: P3 major
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-23 20:40 UTC by q2p0
Modified: 2012-04-24 08:08 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
the preprocessed file (*.i*) that triggers the bug (6.15 KB, application/octet-stream)
2012-04-23 20:40 UTC, q2p0
Details

Note You need to log in before you can comment on or make changes to this bug.
Description q2p0 2012-04-23 20:40:38 UTC
Created attachment 27227 [details]
the preprocessed file (*.i*) that triggers the bug

/*

Exact version of GCC: That I know that version 4.3, 4.6 and 4.7 has this bug.

System Type: x86_32, i686, 32BITS Intel architecture. It don't occurs in 64 bit intel architectures.

Options given when GCC was configured/build: The error happen when you use -std=gnu99 ¡¡BY DEFAULT :O!! standar or -std=gnu89, but not when you use other standar like -std=c99

The complete command line that triggers the bug: "gcc main.c -o main"

The compiler output (error messages, warnings, etc.): None.

the preprocessed file (*.i*) that triggers the bug, generated by adding -save-temps to the complete compilation command, or, in the case of a bug report for the GNAT front end, a complete set of source files (see below): As attachment

Thank's I love GNU & your work a million of thanks.

*/

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

int main(){

	char *cadena = "-25.9";

	//USING A TEMP VARIABLE
	double d = atof(cadena) * 10;
	short s1 = (short) d;
	printf("%d\n",s1); //I GET -259

	//WITHOUT A TEMP VARIABLE
	short s2 = atof(cadena) * 10;
	printf("%d\n",s2); //I GET -258????????????????????????????? WTF?
}
Comment 1 Jonathan Wakely 2012-04-23 21:05:38 UTC
http://gcc.gnu.org/bugs/#nonbugs_general
Comment 2 q2p0 2012-04-23 22:04:15 UTC
But if:

I use one architecture of 64 bits OR
I use the standard -std=99 OR
I use a temporal double variable OR
I compile other compiler that is not GCC

I don't get this error.

Ok I acept the response "This is the result of rounding".
All we know that the nearest representable number for a double (-259.0000) in a short is (-258). I answering me if you really take a look to the code of main.
Comment 3 q2p0 2012-04-23 22:53:56 UTC
#include <iostream>

int main()
{

// Error.
  double a = 0.5;
  double b = 0.01;
  std::cout << (int)(a / b) << std::endl;

// No error.
  double c = a/b;
  std::cout << (int)c << std::endl;

  return 0;
}


* I compile with other...

Sory, about my last sarcastic expresions, and my bad english.
I take a look to the paper when I have time.

Thanks for improve the GNU compiler GCC.
Comment 4 Richard Biener 2012-04-24 08:08:06 UTC
.

*** This bug has been marked as a duplicate of bug 323 ***