File tree Expand file tree Collapse file tree 4 files changed +36
-0
lines changed Expand file tree Collapse file tree 4 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -409,6 +409,8 @@ RUN(NAME test_str_comparison LABELS cpython llvm c)
409409RUN(NAME  test_bit_length     LABELS  cpython llvm c)
410410RUN(NAME  str_to_list_cast    LABELS  cpython llvm c)
411411
412+ RUN(NAME  test_package_01     LABELS  cpython llvm)
413+ 
412414RUN(NAME  generics_01         LABELS  cpython llvm c)
413415RUN(NAME  generics_02         LABELS  cpython llvm c)
414416RUN(NAME  generics_array_01   LABELS  cpython llvm c)
Original file line number Diff line number Diff line change 1+ from  .nr  import  newton_raphson 
Original file line number Diff line number Diff line change 1+ from  ltypes  import  f64 , i32 
2+ 
3+ 
4+ def  func (x : f64 , c : f64 ) ->  f64 :
5+ 	return  x ** 2.0  -  c ** 2.0 
6+ 
7+ 
8+ def  func_prime (x : f64 , c : f64 ) ->  f64 :
9+ 	return  2.0 * x 
10+ 
11+ 
12+ def  newton_raphson (x : f64 , c : f64 , maxiter : i32 ) ->  f64 :
13+ 	h : f64  =  func (x , c ) /  func_prime (x , c )
14+ 	err : f64  =  1e-5 
15+ 	i : i32  =  0 
16+ 	while  abs (func (x , c )) >  err  and  i  <  maxiter :
17+ 		h  =  func (x , c ) /  func_prime (x , c )
18+ 		x  =  x  -  h 
19+ 		i  +=  1 
20+ 	return  x 
Original file line number Diff line number Diff line change 1+ from  nrp  import  newton_raphson 
2+ from  ltypes  import  f64 , i32 
3+ 
4+ 
5+ def  check ():
6+     x0 : f64  =  20.0 
7+     c : f64  =  3.0 
8+     maxiter : i32  =  20 
9+     x : f64 
10+     x  =  newton_raphson (x0 , c , maxiter )
11+     assert  abs (x  -  3.0 ) <  1e-5 
12+ 
13+ check ()
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments