473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

float point properties access

Is there a way in python to access properties of floats? I need something
equiv to C DBL_EPSILON defined in <float.h>.
Jul 18 '05 #1
2 1777
Neal D. Becker wrote:
Is there a way in python to access properties of floats? I need something
equiv to C DBL_EPSILON defined in <float.h>.

you could try the traditional algorithm
def dbl_epsilon(): .... n = 0
.... while 1:
.... e = 1.0/2**n
.... if (1.0+e==1.0): break
.... n += 1
.... pe = e
.... return pe
.... print dbl_epsilon() 2.22044604925e-016


--
Robin Becker
Jul 18 '05 #2
Robin Becker wrote:
Neal D. Becker wrote:
Is there a way in python to access properties of floats? I need
something
equiv to C DBL_EPSILON defined in <float.h>.

you could try the traditional algorithm
>>> def dbl_epsilon(): ... n = 0
... while 1:
... e = 1.0/2**n
... if (1.0+e==1.0): break
... n += 1
... pe = e
... return pe
... >>> print dbl_epsilon() 2.22044604925e-016 >>>


on looking further I find my 'traditional' algorithm is actually
something like this

def dbl_epsilon(_eps=[]):
if not _eps:
etop = 1.0
ebot = 0.0
eps = ebot+(etop-ebot)/2.0
while eps!=ebot and eps!=etop:
epsp1 = 1.0 - eps
if epsp1<1.0: etop = eps
else: ebot = eps
eps = ebot+(etop-ebot)/2.0
_eps.append(etop)
assert (1.0-etop)<1.0 and (1.0-ebot)==1.0, 'Error in epsilon calculation'
return _eps[0]

print dbl_epsilon()

which gives 5.55111512313e-017
-senility is making me stupidly yrs-
Robin Becker
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Erik2000 | last post by:
If someone defines a float and double in C++, does that say anything about how many digits the number will hold at maximum and how many places there will be after the decimal point? Or is this...
12
by: Stan Brown | last post by:
I've been thinking about float-ing a span versus float-ing a div, and the same for absolute positioning. When what is floated or positioned is a short chunk of text, I don't see any _visual_...
53
by: Zhiqiang Ye | last post by:
Hi, All I am reading FAQ of this group. I have a question about this: http://www.eskimo.com/~scs/C-faq/q7.31.html It says: " p = malloc(m * n); memset(p, 0, m * n); The zero fill is...
10
by: pavithra.eswaran | last post by:
Hi, I would like to convert a single precision hexadecimal number to floating point. The following program seems to work fine.. But I do not want to use scanf. I already have a 32 bit hexadecimal...
8
by: David Wade | last post by:
Folks, Well I am still dabling in the mire of math.h and getting on reasonably well. A couple of questions. Firstly when defining some of the extreme values in the many bits of code seem to use...
8
by: bearophileHUGS | last post by:
sys.maxint gives the largest positive integer supported by Python's regular integer type. But maybe such attribute, with few others (they can be called min and max) can be given to int type itself....
116
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused...
45
by: Carramba | last post by:
Hi! I now that I can't do straight forward any bitwise operation on float (double etc..). But I wondering what is the easiest/best way to do this? I was thinking if I have float x=1.1111 so I can...
3
by: Harry | last post by:
Using IE7, I'm trying to display a table in a horizontal manner by floating the rows. The following html does not work, displaying the table vertically as if the rows were not floated. This same...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.