racket/typed-racket

Unsound complex `exp` optimization

Open

#969 opened on Sep 1, 2020

 (3 comments) (0 reactions) (0 assignees)Racket (106 forks)github user discovery
good first issueoptimizerunsound

Repository metrics

Stars
 (576 stars)
PR merge metrics
 (Avg merge 11d 14h) (1 merged PR in 30d)

Description

(exp (log (make-polar 1.7976931348623153e+308 -1.797693134862315e+308)))

produces -8.648665413126592e+306-1.7956115019091953e+308i in Racket but -inf.0-inf.0i after Typed Racket optimization. Optimized code is:

(let-values (((g3)                                        
                    (#%app                                      
                     log                                        
                     (let-values (((g6) '1.7976931348623153e+308))                                                              
                       (let-values (((g7) '-1.797693134862315e+308))                                                            
                         (let-values (((unboxed-real-8)                                                                         
                                       (#%app                   
                                        unsafe-fl*              
                                        g6                      
                                        (#%app unsafe-flcos g7))))                                                              
                           (let-values (((unboxed-imag-9)                                                                       
                                         (#%app                 
                                          unsafe-fl*            
                                          g6                    
                                          (#%app unsafe-flsin g7))))                                                            
                             (#%app                                                                                             
                              unsafe-make-flrectangular         
                              unboxed-real-8                    
                              unboxed-imag-9))))))))            
        (let-values (((unboxed-real-4) (#%app unsafe-flreal-part g3)))                                                          
          (let-values (((unboxed-imag-5) (#%app unsafe-flimag-part g3)))                                                        
            (let-values (((unboxed-scaling-12)                  
                          (#%app unsafe-flexp unboxed-real-4))) 
              (let-values (((unboxed-real-10)                   
                            (#%app                              
                             unsafe-fl*                                                                                         
                             (#%app unsafe-flcos unboxed-imag-5)                                                                
                             unboxed-scaling-12)))              
                (let-values (((unboxed-imag-11)                 
                              (#%app                            
                               unsafe-fl*                                                                                       
                               (#%app unsafe-flsin unboxed-imag-5)                                                              
                               unboxed-scaling-12)))                                                                            
                  (#%app                                        
                   unsafe-make-flrectangular                    
                   unboxed-real-10                              
                   unboxed-imag-11))))))

Disabling the optimization of complex exp might be the right thing.

Originally found here: http://drdr.racket-lang.org/55300/cs/racket/share/pkgs/typed-racket-test/tr-random-testing.rkt

Contributor guide