By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

PC is IEEE754?

P: n/a
As I understand PC with x86 CPU is IEEE754 floating point standart.

Then out of:
<?php
print (19.6*100)!==(double)1960;
?>
will be 1.

It's true ?

Oct 18 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Andrew G. Koptyaev wrote:
As I understand PC with x86 CPU is IEEE754 floating point standart.

Then out of:
<?php
print (19.6*100)!==(double)1960;
?>
will be 1.

It's true ?
Did you try it?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 18 '08 #2

P: n/a
"Andrew G. Koptyaev" <ko******@gmail.comwrote:
>
As I understand PC with x86 CPU is IEEE754 floating point standart.

Then out of:
<?php
print (19.6*100)!==(double)1960;
?>
will be 1.

It's true ?
As Jerry said, you can find out for yourself whether this prints 1 or not.

However, I would like to point out that IEEE-754 compliance does NOT
guarantee the result. 19.6 cannot be represented exactly in binary. In
binary, it is an infinitely repeating value. Thus, the floating point
representation will be an approximation -- very close to 19.6, but not
exactly equal.

When you multiply by 100, it is quite difficult (without knowing the exact
binary representation) to predict whether rounding will help or hurt.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 19 '08 #3

P: n/a
rf

"Andrew G. Koptyaev" <ko******@gmail.comwrote in message
news:gd**********@aioe.org...
As I understand PC with x86 CPU is IEEE754 floating point standart.

Then out of:
<?php
print (19.6*100)!==(double)1960;
Begs the question: Why multiply by 100? Is 19.6 perhaps a $.cents amount? If
so then don't. Store and perform calculations on monetory amounts in
cents(which are always integers and integers are stored exactly in floating
point) and only convert (with suitable rounding) to $s on output.
Oct 19 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.