Can the iPhone do math?

3 views
Skip to first unread message

Craig Morris

unread,
Jan 18, 2010, 7:07:19 PM1/18/10
to Ask Alph
I ran into an interesting problem while implementing the VMG Steam95
package as an option for in app store I am looking at for Alph. This
package reproduces the NIST steam tables and as expected worked like a
charm on the phone simulator. However when I went to run it on an
actual iPhone, it failed, with a flash failure, to calculate the
boiling point of water. Not good.

After much spelunking of some awful old code that has apparently been
only sort of converted from fortran (lots of goto statements -
shudder) I finally discovered that the exp() function on the phone was
returning the wrong answer in some circumstances. For instance:

exp( -3.451682e-06 )

yields 9.939789e-01 while the correct answer should be: 9.999965e-01.
You can confirm this by simply using the standard calculator app that
comes with the iPhone. Once you get the wrong answer, try taking the
ln of it to show that the original number is not returned.

Fortunately there is a simple work around by declaring my own exp
function as:

double exp( double x) {
return pow( 2.718281828,x);
}

It probably isn't as efficient, but if there is a slow down, it hasn't
been noticeable to me. I did file a bug report with Apple, so perhaps
a fix will come in the future.

After discovering this I decided to revisit a problem I had noticed
before in doing flashes at extreme conditions - namely things like dew
points of hydrogen / helium mixtures. I was able to come up with a
case where not only did the flash fail, Alph actually crashed and
quit. After applying the hack above, all was well.

I just released version 1.02 a couple of days ago, so I will probably
wait a decent interval, but look for a 1.03 with this fix shortly.
Fortunately the problem only seems to only raise its head in some
pretty ugly circumstances.

YauKun

unread,
Jan 19, 2010, 2:53:10 PM1/19/10
to al...@googlegroups.com
Hi Craig
Thanks for the info. Wondering if exp() is single precisioned.

--
YauKun Li yau...@virtualMaterials.com
======================================================================================
This e-mail may be privileged and/or confidential, and the sender does not waive any
related rights and obligations.
Any distribution, use or copying of this e-mail or the information it contains by
other than an intended recipient is unauthorized.
If you received this message by mistake, please advise me (by return e-mail or otherwise)
immediately.
======================================================================================

Craig Morris

unread,
Jan 19, 2010, 7:12:13 PM1/19/10
to al...@googlegroups.com
It is declared as a double and it works fine in the simulator and indeed gives identical results in both the phone and simulator in most cases. I just did a little more playing around with the calculator on the phone and it appears that negative numbers with an absolute value smaller than about 3.9e-6 are incorrect.

So it probably is either a glitch in the library function or it might even be a processor problem, for the iPhone uses the Arm processor and perhaps that has a problem.

Craig

Reply all
Reply to author
Forward
0 new messages