Why is hypot1 preferred (in Base) over hypot2 ? To me it seems better to 
just return y    in the one commented line

function hypot2{T<:AbstractFloat}(x::T, y::T)                               
 
    x = abs(x)                                                             
  
    y = abs(y)                                                             
  
    if x < y                                                               
  
        x, y = y, x                                                         
 
    end                                                                     
 
    if x == 0                                                               
 
        return y        ## compare with below                               
                      
    else                                                                   
  
        r = y/x                                                             
 
        if isnan(r)                                                         
 
            isinf(x) && return x                                           
  
            isinf(y) && return y                                           
  
            return r                                                       
  
        end                                                                 
 
    end                                                                     
 
    x * sqrt(one(r)+r*r)                                                   
  
end                                                                         
 


 function hypot1{T<:AbstractFloat}(x::T, y::T)                             
                    
     x = abs(x)                                                             
                   
     y = abs(y)                                                             
                   
     if x < y                                                               
                   
         x, y = y, x                                                       
                    
     end                                                                   
                    
     if x == 0                                                             
                    
         r = y/one(x)   # Why not just return y?                          
     else                                                                   
                   
         r = y/x                                                           
                    
         if isnan(r)                                                       
                    
             isinf(x) && return x                                           
                   
             isinf(y) && return y                                           
                   
             return r                                                       
                   
         end                                                               
                    
     end                                                                   
                    
     x * sqrt(one(r)+r*r)                                                   
                   
 end                                                                       
                    

Reply via email to