Showing posts with label ieee. Show all posts
Showing posts with label ieee. Show all posts

Friday, October 11, 2013

IEEE 754/854, when it is needed

Linkedin

There was a post on linkedin IEEE Computer Society group, lamenting the division by zero exception raised by Python, instead of returning infinity (or -infinity). I replied, but it is not that readable. So I'm putting the properly formatted reply on my blog. [edit: no comments followed on linkedin, but many appeared on the original source after that]

IEEE decimal

If you want IEEE 754/854 decimal behaviour, what you want to use is the decimal module:

>>> import decimal
>>> help(decimal)

The above typed in the python interpreter will provide all the help you need. The examples are a little verbose, however.


ExtendedContext


If you want to be shorthand, you can copy/paste the following at the top of your program:

from decimal import setcontext,ExtendedContext, Decimal as ieee
setcontext(ExtendedContext)


Then whenever you want to use ieee behaviour use ieee(value):

>>> 1/ieee(0)
Infinity
>>> -1/ieee(0)
-Infinity

Python does it right



It is good that it has to be explicitly stated that you want this. A division by zero should raise an exception when dealing with financial data[*]. I would recommend numpy if dealing with scientific data.


François
@f_dion

* Unless you are calculating my bonus...

Thursday, January 3, 2013

RaspberryPi talk @ Winston Salem IEEE

I'll be giving the talk "Raspberry Pi: From Kindergartners To Mad Scientists" at the IEEE Winston Salem chapter:

ewh.ieee.org/r3/winston-salem/

DATE:/TIME Wednesday, January 9th 2013 @ 11:30am  
  
LOCATION:   The Fox and Hound English Pub/Grille. 
Lower Mall Drive, Winston Salem, NC

Same title from PyCarolinas 2012, but it is updated information, and more aligned with my audience of mostly engineers.

I encourage other IEEE members to present a talk on the Raspberry Pi at their local IEEE chapter.