- To: "Carlo Sogono" <carlo@xxxxxxxxxxxxx>
- Subject: Re: [coders] Python newbie question
- From: "Tim Leslie" <tim.leslie@xxxxxxxxx>
- Date: Tue, 14 Nov 2006 12:48:08 +1100
- Cc: coders@xxxxxxxxxxx
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=gEbZPF2S4+tJ2Z3S7kr+rpBzvQdiL1GwrstdlyXF0OQ559vf2h+ommXECx2q/aBGzrW2sxV93yzmqKdxti904PpaxJ0JpxPIej6sQ6oi18qUB0ULxjUPd9rujNZGNf6fFWSDyxP0wHb4gbRw7BkxAeAi+nNcYMOqQLN9m9IMvNk=
On 11/14/06, Carlo Sogono <carlo@xxxxxxxxxxxxx> wrote:
Steve Lindsay wrote:
> I suspect it's related to this:
>
> http://www.python.org/doc/faq/general.html#id34
Thanks. Without having gone through all the links everyone posted, I
have come across this line in your/Tim's link:
"Again, this has nothing to do with Python, but with the way the
underlying C platform handles floating point numbers, and ultimately
with the inaccuracy you'll always have when writing down numbers as a
string of a fixed number of digits."
However I'm pretty sure C applications do not handle floats the same
way. This still gives me a 'normal' response:
int main() {
float a = 8.0, b = 0.45, res;
res = a + b;
printf("%f\n", res);
return (EXIT_SUCCESS);
}
So my new question is, why doesn't C handle floats the same way?
It does.
int main() {
double a = 8.0, b = 0.45, res;
res = a + b;
printf("%1.16f\n", res);
return 0;
}
timl@feynman:~/src$ gcc float.c
timl@feynman:~/src$ ./a.out
8.4499999999999993
Tim
Carlo
_______________________________________________
coders mailing list
coders@xxxxxxxxxxx
http://lists.slug.org.au/listinfo/coders