1

I have a long double in some python code,

In [51]: psr[0]['F0'].val
Out[51]: 205.53069608827314596

I want to set this to a different value, which is also a long double:

In [52]: newparam
Out[52]: 205.53069608827315375

I can add large numbers to the first quantity, eg:

In [53]: psr[0]['F0'].val = psr[0]['F0'].val+1

In [55]: psr[0]['F0'].val
Out[55]: 206.53069608827314596

but i cant get it to take the value of new param:

In [50]: psr[0]['F0'].val=newparam

In [51]: psr[0]['F0'].val
Out[51]: 205.53069608827314596

If i look to see what the 'nextafter' is:

In [61]: np.nextafter(psr[0]['F0'].val, 300)
Out[61]: 205.53069608827314597

So i dont understand why i can't get it to take the value of newparam.. I've got C code that does this, so i'm sure Python must be able to aswell.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
LindleyLentati
  • 161
  • 3
  • 12

1 Answers1

2

It seems alright to me. don't think you quite understand the purpose of nextafter(), here is the doc:

nextafter(x1, x2[, out])

Return the next representable floating-point value after x1 in the direction of x2 element-wise.

usage: Increment a python floating point value by the smallest possible amount

Community
  • 1
  • 1
bpceee
  • 416
  • 4
  • 17
  • Well, i had read the doc on nextafter, which given that the next representable value is a much smaller difference than the change in value im trying to achieve (ie, eps < (val-newval)), is exactly why im confused as to why it wont accept the new value – LindleyLentati Jun 19 '14 at 03:10
  • maybe python treat 205.53069608827314596 and 205.53069608827315375 as the same thing in memory. try: `a = 205.53069608827314596` `b = 205.53069608827315375` `print a==b` – bpceee Jun 19 '14 at 03:30
  • In [8]: a = np.longdouble(205.53069608827314596) In [9]: b = np.longdouble(205.53069608827315375) In [10]: a Out[10]: 205.53069608827314596 In [11]: b Out[11]: 205.53069608827314596 – LindleyLentati Jun 19 '14 at 03:35
  • 1
    so apparently it just cant tell the difference.. but i dont understand why my C code can then.. its running on the same system. – LindleyLentati Jun 19 '14 at 03:37