Using Python from Cocoa App via PyObjc - numbers dont match...

sapsi saptarshi.guha at gmail.com
Wed Nov 8 23:27:01 EST 2006


Hi,
Well not a complaint as such but a question. Thank you for the response
however and the link. I have seen it before but never got around to
reading it...

Further to this, if i was writing a python module and  c function and
suppose the python module and the c  function called each other back
and forth exchanging results from float calculations  - would not the
results then become flawed? How would one pass floats between different
languages - using special purpose data structures understood by both
the python module and c code?

I asked this question without reading the link, so if it stinks of
ignorance please forget it.

Thank you
Saptarshi


Michael Ash wrote:
> In comp.lang.objective-c sapsi <saptarshi.guha at gmail.com> wrote:
> > The first output in the console is 40.4 and the second
> > -40.40000152587891.
> >
> > If i change the NSLog(s)  to "%f",[n floatValue] (and the second
> > likewise) the first is 40.400002 and the second is -40.400002.
>
> I assume you are complaining about the fact that it's not printing exactly
> 40.4, and wondering where the error is coming from. (It helps if you
> actually state this yourself, so we don't have to assume it, rather than
> just laying out the circumstances.)
>
> The answer is that floating point numbers are inherently imprecise. Read
> through this essential resource:
>
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
> 
> -- 
> Michael Ash
> Rogue Amoeba Software




More information about the Python-list mailing list