"""Utilities for handling IEEE 754 floating point special values This python module implements constants and functions for working with IEEE754 double-precision special values. It provides constants for Not-a-Number (NaN), Positive Infinity (PosInf), and Negative Infinity (NegInf), as well as functions to test for these values. The code is implemented in pure python by taking advantage of the 'struct' standard module. Care has been taken to generate proper results on both big-endian and little-endian machines. Some efficiency could be gained by translating the core routines into C. See for reference material on the IEEE 754 floating point standard. Further information on this package is available at . Author: Gregory R. Warnes Date:: 2003-04-08 Copyright: (c) 2003, Pfizer, Inc. """ __version__ = "0.6.0" ident = "$Id: fpconst.py,v 1.8 2003/05/12 15:14:00 warnes Exp $" import struct # check endianess _big_endian = struct.pack('i',1)[0] != '\x01' # and define appropriate constants if(_big_endian): _HW = 0 _LW = 1 NaN = struct.unpack('d', '\x7F\xFF\xFF\xFF\xFF\xFF\xFF\xFF')[0] PosInf = struct.unpack('d', '\x7F\xF0\x00\x00\x00\x00\x00\x00')[0] NegInf = -PosInf else: _HW = 1 _LW = 0 NaN = struct.unpack('d', '\x00\x00\x00\x00\x00\x00\xf8\xff')[0] PosInf = struct.unpack('d', '\x00\x00\x00\x00\x00\x00\xf0\x7f')[0] NegInf = -PosInf def _double_as_longs(dval): "Use struct.unpack to decode a double precision float into two longs" tmp = struct.unpack('ll',struct.pack('d', dval)) return (tmp[_HW], tmp[_LW]) ## ## Functions to extract components of the IEEE 754 floating point format ## def _sign(dval): "Extract the sign bit from a double-precision floating point value" ll = _double_as_longs(dval) return ll[0] >> 31 & 0x01 def _exponent(dval): """Extract the exponentent bits from a double-precision floating point value. Note that for normalized values, the exponentdent bits have an offset of 1023. As a consequence, the actual exponentent is obtained by subtracting 1023 for the value returned by this function """ ll = _double_as_longs(dval) return (ll[0] >> 20) & 0x7ff def _mantissa(dval): """Extract the _mantissa bits from a double-precision floating point value.""" ll = _double_as_longs(dval) mantissa0 = (ll[0] & 0x000fffffL) << 32 mantissa1 = ll[1] return mantissa0 + mantissa1 ## ## Functions to test for IEEE 754 special values ## def isNaN(value): "Determine if the argument is a IEEE 754 NaN (Not a Number) value." return (_exponent(value)==0x7ff and _mantissa(value)!=0) def isInf(value): """Determine if the argument is an infinite IEEE 754 value (positive or negative inifinity)""" return (_exponent(value)==0x7ff and _mantissa(value)== 0) def isFinite(value): """Determine if the argument is an finite IEEE 754 value (i.e., is not NaN, positive or negative inifinity)""" return (_exponent(value)!=0x7ff) def isPosInf(value): "Determine if the argument is a IEEE 754 positive infinity value" return (_sign(value)==0 and _exponent(value)==0x7ff and \ _mantissa(value)== 0) def isNegInf(value): "Determine if the argument is a IEEE 754 negative infinity value" return (_sign(value)==1 and _exponent(value)==0x7ff and \ _mantissa(value)== 0) 23:55:12 +0000'>2009-01-24tcltk: Fix the native packages after last tcltk changeTim Ellis2 2009-01-24tcltk: 8.4.11 -> 8.4.19; try harder to get proper library packagingMichael 'Mickey' Lauer5 2009-01-01tk-native: Reordered lines to fix dependencies.Stanislav Brabec1 2008-12-16tcl-native, tk-native: New packages. Needed for compilation of geda/pcb.Stanislav Brabec2 2008-10-18bb files: Revert the introduction of FILE_PRHolger Hans Peter Freyther2 2008-10-15[PR] Change PR to FILE_PR and intro PR as FILE_PR + DISTRO_PRHolger Hans Peter Freyther2 2008-10-15mtn2git: remove .mtn2git_empty files in non-empty directoriesJan Luebbe4 2008-02-21tcl: drop -L${libdir} in tclConfig.sh. Fixes 3771. Thanks, zecke.Rolf Leggewie1 2007-01-06tcl: make sure ${STAGING_BINDIR_CROSS} exists before trying to install tclCon...Rod Whitby1 2006-11-29Introduce STAGING_BINDIR_CROSS and STAGING_BINDIR_NATIVE as discussed on the ...Richard Purdie2 2006-09-29tk: fix dirs in tkConfig.sh so tk related stuff will be buildable after clean...Marcin Juszkiewicz1 2006-09-29tcl: fix dirs in tclConfig.sh so tcl related stuff will be buildable after cl...Marcin Juszkiewicz1 2006-07-29x11: change virtual/x11 to virtual/libx11Justin Patrin1 2006-07-26x11: switch to virtual/x11 so that diet or full x11 can be selectedJustin Patrin1 2006-07-24tcl - Fix for a crazy configure script in TCL.Raymond Danks1 2006-05-13tk: depend on libxt - close #966Marcin Juszkiewicz1 2006-04-16tcl/tk: add pnum=2 to make the latest patch applyKoen Kooi2 2006-04-16tcltk: apply patch to fix a bogus line in the configure scriptsMichael Lauer6 2006-03-01all over the place: adapt DEPENDS to new xlib namesPhilipp Zabel1 2005-09-26disapproval of revision 05dd4ce9d2ee0995688e45e60a21534114fbc45fMichael Lauer1 2005-09-26tk: DEPEND on libx11, not x11Michael Lauer1 2005-09-25tcl/tk: add SONAME patches, ship .so in $PN, not $PN-devMichael Lauer4 2005-09-25tcl/tk: install header files into $STAGING_DIRMichael Lauer2 2005-09-24add tcl (tool command language) and the tk (toolkit) extensionMichael Lauer5