Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

Math.sqrt(-1) -- nan or ValueError?

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


hasan.diwan at gmail

Sep 4, 2007, 2:43 PM

Post #1 of 4 (290 views)
Permalink
Math.sqrt(-1) -- nan or ValueError?

I'm trying to fix a failing unit test in revision 57974. The test in
question claims that math.sqrt(-1) should raise ValueError; the code itself
gives "nan" as a result for that expression. I can modify the test and
therefore have it pass, but I'm not sure if an exception would be more
appropriate. I'd be happy for some direction here. Many thanks!

--
Cheers,
Hasan Diwan <hasan.diwan [at] gmail>


guido at python

Sep 4, 2007, 2:58 PM

Post #2 of 4 (266 views)
Permalink
Re: Math.sqrt(-1) -- nan or ValueError? [In reply to]

Is this on OSX? That test has been failing (because on that platform
sqrt(-1) returns nan instead of raising ValueError) for years -- but
the test is only run when run in verbose mode, which mostly hides the
issue. Have you read the comment for the test?

On 9/4/07, Hasan Diwan <hasan.diwan [at] gmail> wrote:
> I'm trying to fix a failing unit test in revision 57974. The test in
> question claims that math.sqrt(-1) should raise ValueError; the code itself
> gives "nan" as a result for that expression. I can modify the test and
> therefore have it pass, but I'm not sure if an exception would be more
> appropriate. I'd be happy for some direction here. Many thanks!

--
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


hasan.diwan at gmail

Sep 4, 2007, 3:13 PM

Post #3 of 4 (268 views)
Permalink
Re: Math.sqrt(-1) -- nan or ValueError? [In reply to]

On 04/09/07, Guido van Rossum <guido [at] python> wrote:
>
> Is this on OSX? That test has been failing (because on that platform
> sqrt(-1) returns nan instead of raising ValueError) for years -- but
> the test is only run when run in verbose mode, which mostly hides the
> issue. Have you read the comment for the test?


Indeed, I am on OSX. Yes, I have read the comment for the test. Would the
following pseudocode be an acceptable fix for the problem:
if sys.platform == 'darwin' and math.sqrt(-1) == nan:
return
else:
try:
x = math.sqrt(-1)
except ValueError:
pass
...
or should I just not bother?
--
Cheers,
Hasan Diwan <hasan.diwan [at] gmail>


guido at python

Sep 4, 2007, 3:45 PM

Post #4 of 4 (268 views)
Permalink
Re: Math.sqrt(-1) -- nan or ValueError? [In reply to]

I think it's better for the test to fail, to indicate that there's an
unresolved problem on the platform.

On 9/4/07, Hasan Diwan <hasan.diwan [at] gmail> wrote:
> On 04/09/07, Guido van Rossum <guido [at] python> wrote:
> > Is this on OSX? That test has been failing (because on that platform
> > sqrt(-1) returns nan instead of raising ValueError) for years -- but
> > the test is only run when run in verbose mode, which mostly hides the
> > issue. Have you read the comment for the test?
>
> Indeed, I am on OSX. Yes, I have read the comment for the test. Would the
> following pseudocode be an acceptable fix for the problem:
> if sys.platform == 'darwin' and math.sqrt(-1) == nan:
> return
> else:
> try:
> x = math.sqrt(-1)
> except ValueError:
> pass
> ...
> or should I just not bother?
> --
> Cheers,
>
> Hasan Diwan < hasan.diwan [at] gmail>


--
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-Dev mailing list
Python-Dev [at] python
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.