My personal preference is for code to never raise warnings if you might ever 
use it in a system that has more than 10 lines of code. So I'm personally a 
believer in either returning NaN without a warning (which seems a little risky) 
or maintaining the current behavior, which seems wisest to me.

 -- John

On Nov 4, 2014, at 9:22 AM, [email protected] wrote:

> I have recently become aware of Julia and have been impressed with its ease 
> of use and speed.  While I was converting my previous code to Julia, I 
> noticed that trigonometric functions at infinity yield DomainError and abort 
> the program. Try sin(Inf), sin(-Inf), cos(Inf), tan(Inf), etc.  I checked the 
> behavior of Numpy and it returns a NaN and a warning of invalid value to the 
> function. I remember Matlab was yielding a NaN too. But they both wouldn't 
> abort the program.
> 
> Returning a NaN instead of aborting the program might be useful when the 
> following computations don't depend on only this result of NaN.  For example, 
> consider finding the smallest element of x =cos( [1.0, 2.0, Inf]) which would 
> have given the number I am interested in if cos(Inf) gives a NaN.  Here I 
> cos(2.0) < NaN would be false nevertheless findmin cleverly finds the correct 
> answer 2.0 ( so does Numpy). Note that Inf is usually a result of an 
> intermediate step of an algorithm.
> 
> If the following computations involve NaN and yield compilation error than 
> checking elements of x being not NaN is necessary. But since it does occur 
> rarely, avoiding this check might be useful for speed.
> 
> What would be your thoughts?  Thanks.
> 

Reply via email to