签名零:这是一个错误吗? [英] Signed zeros: is this a bug?
问题描述
我在Python 2.5上获得了以下行为(PowerPC上的OS X 10.4.8,如果它相关,则为
。)
< blockquote class =post_quotes>
>> x,y = 0.0,-0.0
x,y
(0.0,0.0)
> ;> x,y = -0.0,0.0
x,y
(-0.0,-0.0)
我希望在第一种情况下y为-0.0,在
秒内为0.0。如果以上被认为是一个错误,或者Python不是b $ b预计会尊重零的迹象?我正在工作的情况
涉及复杂的算术,其中分支削减,因此签署
零,很重要,如果上面的代码可能会很方便
依靠做正确的事。
Mark
3月11日上午9:31,Mark Dickinson < dicki ... @ gmail.comwrote:
我在Python 2.5上得到以下行为(PowerPC上的OS X 10.4.8,
,如果它是相关的。)
> x,y = 0.0,-0.0
x ,y
(0.0,0.0)
> x,y = -0.0,0.0
x,y
(-0.0,-0.0)
我希望在第一种情况下y为-0.0,在
秒内为0.0。如果以上被认为是一个错误,或者Python不是b $ b预计会尊重零的迹象?我正在工作的情况
涉及复杂的算术,其中分支削减,因此签署
零,很重要,如果上面的代码可能会很方便
依靠做正确的事。
IIRC,float .__ repr__就像libc所做的一样。您是否在C程序中使用printf(%g,%g,0.0,-0.0)尝试了
?
< blockquote> 2007年3月11日星期日10:31,Mark Dickinson
写道:
我在Python 2.5上获得以下行为(OS <如果它是相关的,请在PowerPC上获得
X 10.4.8。)
> x ,y = 0.0,-0.0
x,y
(0.0,0.0)
> x,y = -0.0,0.0
x,y
(-0.0,-0.0)
我原本预计在第一个
情况下y为-0.0,在第二个情况下为0.0。如果上面的
被认为是一个错误,或者Python是不是预期
来纪念零的迹象?我正在处理一个涉及复杂算术的
情况,其中
分支削减,因此签名零,
重要,它会如果上面的
代码可以依赖来做正确的
的事情就好用。
Mark
这可以用于某种原因
而不是x,y = -0.0,0.0
clumpy但结果是对的。
x = -0.0
y = 0.0
x,y
(-0.0,0.0)
jim-on-linux
http:\\inqvista.com
" Dan Bishop" < da ***** @ yahoo.comwrote in message
news:11 ********************* @ 30g2000cwc.googlegrou ps.com ...
| 3月11日上午9:31,Mark Dickinson < dicki ... @ gmail.comwrote:
|我在Python 2.5上获得了以下行为(PowerPC上的OS X 10.4.8,
|如果它是相关的。)
| >
| > x,y = 0.0,-0.0
| > x,y
| (0.0,0.0)
| > x,y = -0.0,0.0
| > x,y
| >
| (-0.0,-0.0)
|| IIRC,float .__ repr__就像libc那样做。你试过
|在C程序中使用printf(%g,%g,0.0,-0.0)?
这样的详细FP行为依赖于系统(和是,libc)。 On
WinXP
IDLE 1.1.3
>> x,y = 0.0,-0.0
x,y
(0.0, 0.0)
>> x,y = -0.0,0.0
x,y
(0.0,0.0)
>> -0.0
0.0
Terry Jan Reedy
I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC,
in case it''s relevant.)
>>x, y = 0.0, -0.0
x, y
(0.0, 0.0)
>>x, y = -0.0, 0.0
x, y
(-0.0, -0.0)
I would have expected y to be -0.0 in the first case, and 0.0 in the
second. Should the above be considered a bug, or is Python not
expected to honour signs of zeros? I''m working in a situation
involving complex arithmetic where branch cuts, and hence signed
zeros, are important, and it would be handy if the above code could be
relied upon to do the right thing.
Mark
On Mar 11, 9:31 am, "Mark Dickinson" <dicki...@gmail.comwrote:I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC,
in case it''s relevant.)
>x, y = 0.0, -0.0
x, y
(0.0, 0.0)
>x, y = -0.0, 0.0
x, y
(-0.0, -0.0)
I would have expected y to be -0.0 in the first case, and 0.0 in the
second. Should the above be considered a bug, or is Python not
expected to honour signs of zeros? I''m working in a situation
involving complex arithmetic where branch cuts, and hence signed
zeros, are important, and it would be handy if the above code could be
relied upon to do the right thing.IIRC, float.__repr__ just does whatever libc does. Have you tried
using printf("%g, %g", 0.0, -0.0) in a C program?
On Sunday 11 March 2007 10:31, Mark Dickinson
wrote:I get the following behaviour on Python 2.5 (OS
X 10.4.8 on PowerPC, in case it''s relevant.)
>x, y = 0.0, -0.0
x, y
(0.0, 0.0)
>x, y = -0.0, 0.0
x, y
(-0.0, -0.0)
I would have expected y to be -0.0 in the first
case, and 0.0 in the second. Should the above
be considered a bug, or is Python not expected
to honour signs of zeros? I''m working in a
situation involving complex arithmetic where
branch cuts, and hence signed zeros, are
important, and it would be handy if the above
code could be relied upon to do the right
thing.
Mark
This works for some reason
instead of x,y = -0.0, 0.0
clumpy but the results are right.
x = -0.0
y= 0.0
x,y
(-0.0, 0.0)
jim-on-linux
http:\\inqvista.com
"Dan Bishop" <da*****@yahoo.comwrote in message
news:11*********************@30g2000cwc.googlegrou ps.com...
| On Mar 11, 9:31 am, "Mark Dickinson" <dicki...@gmail.comwrote:
| I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC,
| in case it''s relevant.)
| >
| >x, y = 0.0, -0.0
| >x, y
| (0.0, 0.0)
| >x, y = -0.0, 0.0
| >x, y
| >
| (-0.0, -0.0)
|| IIRC, float.__repr__ just does whatever libc does. Have you tried
| using printf("%g, %g", 0.0, -0.0) in a C program?
Detailed FP behavior like this is system (and yes, libc) dependent. On
WinXP
IDLE 1.1.3>>x,y = 0.0, -0.0
x,y
(0.0, 0.0)
>>x,y = -0.0, 0.0
x,y
(0.0, 0.0)
>>-0.0
0.0
Terry Jan Reedy
这篇关于签名零:这是一个错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!