473,699 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Signed zeros: is this a bug?

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

Mar 11 '07
38 2280
al***@mac.com (Alex Martelli) writes:
Incidentally (and I know you know that, Paul, but others interested in
this thread might not) fast exact rational arithmetic (based on the LGPL
library named GMP) is supplied, among other functionality, by module
gmpy, currently found at http://code.google.com/p/gmpy/ (this version is
more recent than the older one at sourceforce, which for some reason
doesn't let me update things right any more).
For some reason setuptools isn't finding it:

jupiter:~ # easy_install gmpy
Searching for gmpy
Reading http://cheeseshop.python.org/pypi/gmpy/
Reading http://code.google.com/p/gmpy/
Reading http://cheeseshop.python.org/pypi/gmpy/1.02
No local packages or download links found for gmpy
error: Could not find suitable distribution for Requirement.par se('gmpy')
I believe that setuptools isn't ready to find packages on code.google.com
yet... ;-)

--
Jorge Godoy <jg****@gmail.c om>
Mar 12 '07 #31
Jorge Godoy <jg****@gmail.c omwrote:
al***@mac.com (Alex Martelli) writes:
Incidentally (and I know you know that, Paul, but others interested in
this thread might not) fast exact rational arithmetic (based on the LGPL
library named GMP) is supplied, among other functionality, by module
gmpy, currently found at http://code.google.com/p/gmpy/ (this version is
more recent than the older one at sourceforce, which for some reason
doesn't let me update things right any more).

For some reason setuptools isn't finding it:

jupiter:~ # easy_install gmpy
Searching for gmpy
Reading http://cheeseshop.python.org/pypi/gmpy/
Reading http://code.google.com/p/gmpy/
Reading http://cheeseshop.python.org/pypi/gmpy/1.02
No local packages or download links found for gmpy
error: Could not find suitable distribution for Requirement.par se('gmpy')
I believe that setuptools isn't ready to find packages on code.google.com
yet... ;-)
I'm not familiar with setuptools, what exactly is it looking for?

If it's looking for stuff to download it should start at

http://code.google.com/p/gmpy/downloads/list

(but what does it want -- the sources' zipfile, or some binary, and in
what format and with what naming convention?) -- I'll be glad to edit
the URL for gmpy at cheeseshop if some setuptools expert can explain
these subtleties... thanks for pointing out that there's a problem
btw!-)
Alex
Mar 12 '07 #32
al***@mac.com (Alex Martelli) writes:
I'm not familiar with setuptools, what exactly is it looking for?

If it's looking for stuff to download it should start at

http://code.google.com/p/gmpy/downloads/list

(but what does it want -- the sources' zipfile, or some binary, and in
what format and with what naming convention?) -- I'll be glad to edit
the URL for gmpy at cheeseshop if some setuptools expert can explain
these subtleties... thanks for pointing out that there's a problem
btw!-)
Thanks for caring ;-)
It looks for several things: eggs (for the Python version it is being used),
zipfiles and tarballs (I dunno if it looks for more things).

If it finds, for example, gmpy-1.0.2-py2.4.egg it won't install here 'cause I
use Python 2.5 and then it will continue searching for gmpy-1.0.2-py2.5.egg or
an alternative format that can be used. The last resort is the tarball / zip
with the sources so that the package can be rebuilt.

Probably other people that are more experienced with it can help more. I'm
more an end user of it and I know the essential for my needs.

I just pointed out because setuptools helps a lot on obtaining a package and
installing it (even if there's some building needed before installing).
Sorry for not being able to help more.
With regards to the hyperlink, I believe that if the link on Pypi was to the
URL above it would be easier. Another alternative is a link at the first
page. And, of course, the last alternative is teaching setuptools how to work
with code.google.com -- if it doesn't already know -- as it learnt how to work
with SourceForge and its "random" mirrors. I don't know how to write that
code, though.
Be seeing you,
--
Jorge Godoy <jg****@gmail.c om>
Mar 12 '07 #33
Jorge Godoy <jg****@gmail.c omwrote:
...
these subtleties... thanks for pointing out that there's a problem
btw!-)

Thanks for caring ;-)
Hey, I'd just love to make it as easy as possible to get gmpy -- that's
why I (shudder!-) even build and upload Windows installers...

It looks for several things: eggs (for the Python version it is being used),
zipfiles and tarballs (I dunno if it looks for more things).

If it finds, for example, gmpy-1.0.2-py2.4.egg it won't install here 'cause I
use Python 2.5 and then it will continue searching for gmpy-1.0.2-py2.5.egg or
an alternative format that can be used. The last resort is the tarball / zip
with the sources so that the package can be rebuilt.
OK, the .zip file IS there -- I don't know how to build .egg ones but of
course I could study up on it -- can you suggest a URL?

To be usable on Windows w/o effort, the packaged format must contain a
..pyd (and, on Mac, a .so, etc). Can a .egg deal w/that?

I need to find out w/certainty, because once I've uploaded a file w/a
certain name I can't change the name, nor the contents -- the URLs on
code.google.com are meant to be permanent...
Probably other people that are more experienced with it can help more. I'm
more an end user of it and I know the essential for my needs.

I just pointed out because setuptools helps a lot on obtaining a package and
installing it (even if there's some building needed before installing).
OK, but since most Windows users don't have a suitable C compiler, and
many Mac ones never bother installing the C compiler that comes with
their OS DVDs, if I'm to make things easy I definitely need to pack up
binaries. How do I pack binaries (for dynamic link libraries) that need
to be very different on Win, Mac, various Linux distros...?
Sorry for not being able to help more.
With regards to the hyperlink, I believe that if the link on Pypi was to the
URL above it would be easier. Another alternative is a link at the first
page. And, of course, the last alternative is teaching setuptools how to work
with code.google.com -- if it doesn't already know -- as it learnt how to work
with SourceForge and its "random" mirrors. I don't know how to write that
code, though.
Me neither, knowing near to nothing about setuptools (I'm not even a
user of it...). Let's hope some expert does speak up -- I can't just
freely experiment with uploads and the like...
Alex
Mar 12 '07 #34
On Mar 11, 9:56 pm, a...@mac.com (Alex Martelli) wrote:
That bug isn't formally closed yet, and the discussion's going on, we'll
see. Meanwhile can you try my patch 1678668 just to double check it
does fix everything? (It's agains the current HEAD of Python's svn).
It does, and all tests pass. (Still on OS X 10.4.8/PowerPC; I'll
test
it tomorrow on my Linux machine at work.)

Mark

Mar 12 '07 #35
On Mar 11, 10:49 pm, "Paddy" <paddy3...@goog lemail.comwrote :
On Mar 11, 9:28 pm, Paul Rubin <http://phr...@NOSPAM.i nvalidwrote:
Dennis Lee Bieber <wlfr...@ix.net com.comwrites:
Pardon? What is "the right thing with signed zeros"... In the last
30 years I've been on machines that normalize floating zero into a true
zero (all bits are zero: mantissa, exponent, and sign). This is the
first time I've even seen a variable output as a negative 0.0!
Most machines these days use IEEE 754 which supports negative zero.
http://en.wikipedia.org/wiki/Negative_zero

Isn't negative zero mathematically the same as zero? Isn't -0 just an
artefact of the representation of floating point numbers? Shouldn't
f(0) == f(-0) for all functions f?
I read the wikipedia article about meteorologists using -0 to denote a
negative number rounded to zero for the purposes of binning, i.e. if
you want to tally days with temperature above and below zero, but it
doesn't seem right. You should arrange for any temperature to be in
only one range and record temperatures to their determined accuracy. a
temperature of zero would only be in one bin and if a temperature is
read as -0.2 and th rounding says it should be taken as zero then it
should go in the same bin as any positive reading that is rounded to
zero.
Getting back to Python, shouldn't we strive to remove any distinction?
a zero is a zero regardless of sign and a function like atan returning
one of two different vaues for an argument of zero is actually
mathematically not a bad thing to do?

- Paddy.
A big thanks to Paul and Andre,
I think I have it now. The OP is investigating multivalued functions
where the function converges to different values when approached from
different directions. Floating point arithmetic being a best
compromise solution to the rational number system, distinguishes
between zero and minus zero as an important part of the compromise.
The OP wants to compute a function of zero and minus zero distinctly
and is hampered by Python not preserving the zero/minus zero
distinction in some cases - hence it being a bug.

Swell, Ta!

- Paddy.

Hey, I'm still learnin'. Sweet!

Mar 12 '07 #36
al***@mac.com (Alex Martelli) writes:
Hey, I'd just love to make it as easy as possible to get gmpy -- that's
why I (shudder!-) even build and upload Windows installers...
Brave man! :-)
OK, the .zip file IS there -- I don't know how to build .egg ones but of
course I could study up on it -- can you suggest a URL?
The .egg is nice because it can be an already built binary.

http://peak.telecommunity.com/DevCenter/setuptools

The URL above contains examples and instructions on how to use setuptools.
To be usable on Windows w/o effort, the packaged format must contain a
.pyd (and, on Mac, a .so, etc). Can a .egg deal w/that?
Yes. I have a .egg that has a .so here, for rpy (http://rpy.sf.net/).
I need to find out w/certainty, because once I've uploaded a file w/a
certain name I can't change the name, nor the contents -- the URLs on
code.google.com are meant to be permanent...
Hmmm... I'd suggest you to build only locally then... I don't like this kind
of "permanent" things. They could have a flag "publish this" to make it
permanent and make the standard "unpublishe d". Here's a suggestion for you to
forward there inside Google... ;-)
OK, but since most Windows users don't have a suitable C compiler, and
many Mac ones never bother installing the C compiler that comes with
their OS DVDs, if I'm to make things easy I definitely need to pack up
binaries. How do I pack binaries (for dynamic link libraries) that need
to be very different on Win, Mac, various Linux distros...?
One build per platform would be my choice. Packing everything together would
make the package too big (specially if you start supporting other OSs).
Me neither, knowing near to nothing about setuptools (I'm not even a
user of it...). Let's hope some expert does speak up -- I can't just
freely experiment with uploads and the like...
Lets wait. ;-)

Thanks again,
--
Jorge Godoy <jg****@gmail.c om>
Mar 12 '07 #37
al***@mac.com (Alex Martelli) writes:
This is not trivial to fix cleanly...:-(. compiler_add_o would have
to test "is the object I'm storing -0.0" (I don't even know how to
do that in portable C...) and then do some kludge -- e.g. use as the
key into the dict (-0.0, 0) instead of (-0.0, float) for this one
special case.
Another way, which avoids making this decision, is to always store the
sign *and* value of the number as part of the key. I don't know if
that tradeoff is the right one though.

--
\ "Our products just aren't engineered for security." -- Brian |
`\ Valentine, senior vice-president of Microsoft Windows |
_o__) development |
Ben Finney

Mar 12 '07 #38
"Paddy" <pa...y3***@goo glemail.comwrot e
>
Hey, I'm still learnin'. Sweet!
contrary to popular belief, the answer to life,
the universe, happiness and everything is
not 42, but the above.

- Hendrik

Mar 13 '07 #39

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

Similar topics

8
2738
by: TheTeapot | last post by:
Hi all, Here's a puzzle: // Say I have an array of numbers set up like so: $arr = array(15,16,17,100,121,1000); // How can I create a function so that I can use it like so: addleadingzeros_arr($arr); // and have the output look like:
5
11506
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in anticipation, Regards,
4
2657
by: Ken Tough | last post by:
Seems like a simple thing to find out, but I'm struggling. I have googled, but everything I find is about implicit conversion, not explicit. Is this implementation-specific, or does ANSI/ISO lay out what should happen for: -------------------------- signed char sc; unsigned char uc;
2
1595
by: Teep | last post by:
I have a simple text box called txtrefnum, if the user enters a number length less than 9 characters long than I need to have lead zeros added to it. Does anyone know how to do this? I couldn't find anything online on the subject... <asp:TextBox id="txtRefNum" runat="server"></asp:TextBox> I thought I could use a validator for the process and make the user add the zeros, but of course that is a big no-no! Please help!!
6
1411
by: TN Bella | last post by:
I have a simple text box called txtrefnum, if the user enters a number length less than 9 characters long than I need to have lead zeros added to it. Does anyone know how to do this? I couldn't find anything online on the subject... <asp:TextBox id="txtRefNum" runat="server"></asp:TextBox> I thought I could use a validator for the process and make the user add the zeros, but of course that is a big no-no! Please help!!
15
20097
by: Bob | last post by:
I'm about to convert to string and use regex, but I thought there must be something I'm missing here that already exists. Bob
18
1749
by: Susan Rice | last post by:
I'm comparing characters via return(str1 - str2); and I'm having problems with 8-bit characters being treated as signed instead of unsigned integers. The disassembly is using movsx eax,byte ptr to load my character in to EAX register. I need it to use movzx.
6
7758
by: JimmyKoolPantz | last post by:
Task: Customer wants a script of the data that was processed in a "CSV" file. Problem: Zip-Code leading zeros are dropped Basically we have a client that has requested a custom script for each file that he has us process. He wants this in a Comma Delimited Format.
3
9919
by: ManuelValdez | last post by:
Hello everybody! I need your valuable help to get an Excel macro to delete the single zeros only and no the zeros containing numbers like 360, 90, etc., because if I chose the search and replace in the Edit option, then all the zeros containing the numbers 360, 90, 502, etc. will be deleted. Some nice person helped me with the following code to delete the zeros: Selection.Replace What:="0", Replacement:="" , but unfortunately this code...
0
8618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9178
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8885
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7752
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2348
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.