"1" vs "1.0f" - makes a difference?

Started by
31 comments, last by Cromulent 15 years, 9 months ago
Quote:Original post by dmail
Quote:Original post by ApochPiQ
Neither of your tests will cause an obvious problem with coercing them to floats from doubles. Try something like 1e50 which is out of float's range, and you'll get a warning (unless you're being stupid and not runnning with a high warning level).


Quote:
dmail@x1-6-00-11-2f-24-88-81:~/gcc_warning> gcc -ansi -pedantic -pedantic-errors -Wall -Wextra float_double.c
float_double.c: In function ‘main’:
float_double.c:5: warning: unused variable ‘f2’
float_double.c:4: warning: unused variable ‘f1’
float_double.c:3: warning: unused variable ‘f’
dmail@x1-6-00-11-2f-24-88-81:~/gcc_warning> cat float_double.c
int main()
{
float f = 1.0/3.0;
float f1 = 56355465468487.3;
float f2 = 1e50;
return 0;
}
dmail@x1-6-00-11-2f-24-88-81:~/gcc_warning>

Why would I be being stupid? you can see the error and warning flags I am passing to the compiler.

Same code, but with icc in place of gcc :
Quote:
arkhyl@zeus:~$ icc -ansi -Wall -o test float_double.c
float_double.c(3): remark #810: conversion from "double" to "float" may lose significant bits
float f = 1.0/3.0;
^
float_double.c(5): warning #264: floating-point value does not fit in required floating-point type
float f2 = 1e50;
^
float_double.c(3): remark #177: variable "f" was declared but never referenced
float f = 1.0/3.0;
^
float_double.c(4): remark #177: variable "f1" was declared but never referenced
float f1 = 56355465468487.3;
^
float_double.c(5): remark #177: variable "f2" was declared but never referenced
float f2 = 1e50;

It seems gcc does something wrong.
Advertisement
Quote:Original post by dmail
Quote:
dmail@x1-6-00-11-2f-24-88-81:~/gcc_warning> gcc -ansi -pedantic -pedantic-errors -Wall -Wextra float_double.c
float_double.c: In function ‘main’:
float_double.c:5: warning: unused variable ‘f2’
float_double.c:4: warning: unused variable ‘f1’
float_double.c:3: warning: unused variable ‘f’
dmail@x1-6-00-11-2f-24-88-81:~/gcc_warning> cat float_double.c
int main()
{
float f = 1.0/3.0;
float f1 = 56355465468487.3;
float f2 = 1e50;
return 0;
}
dmail@x1-6-00-11-2f-24-88-81:~/gcc_warning>

Why would I be being stupid? you can see the error and warning flags I am passing to the compiler.


I also get the same behaviour with gcc-4.2.3 using C++, which I was little surprised about. I tried to poke it but without any luck...

philpalk@innerchild:~$ g++ -ansi -pedantic -pedantic-errors -Wall -Wextra main.cppphilpalk@innerchild:~$ cat main.cppdouble dostuff(float f){  return f;}int main(){  float f = 1e50;  double d = 1e50;  f = d;  f = dostuff(1e50);}philpalk@innerchild:~$ 
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Interesting thread. Some useful information here. The link that was posted earlier about floating point numbers was especially helpful.

As an aside it makes me laugh that I got rated down for clarifying a position which turned out was wrong. Hardly an unhelpful post.

This topic is closed to new replies.

Advertisement