Q&A's, tips, howto's
			
		
		
			
				
																			
								cameyo 							 
									
		Posts:  183 Joined:  Sun Mar 27, 2011 3:07 pmLocation:  Italy
				Contact: 
				
			 
				
		 
		
						
						
													
							
						
									
						Post 
					 
								by cameyo  Mon Oct 19, 2020 9:11 am 
			
			
			
			
			I have some problems with the 
pow  function:
Code: Select all 
(pow 3 0.33)
;-> 1.436977652184852
(pow -3 0.33)
;-> 1.#IND
In Mathematica (WolframAlpha):
Code: Select all 
 3^0.33 = 1.436977652184852
-3^0.33 = -1.436977652184852
A simple solution:
Code: Select all 
(define (pow-ext x n)
  (if (< x 0)
      (sub 0 (pow (sub 0 x) n))
      (pow x n)))
(pow-ext 3 0.33)
;-> 1.436977652184852
;(pow-ext -3 0.33)
;-> -1.436977652184852
Why newLISP result is 1.#IND?
 
		 
				
		
		 
	 
	
		
		
			
				
																			
								Lutz 							 
									
		Posts:  5289 Joined:  Thu Sep 26, 2002 4:45 pmLocation:  Pasadena, California
				Contact: 
				
			 
				
		 
		
						
						
													
							
						
									
						Post 
					 
								by Lutz  Mon Oct 19, 2020 3:24 pm 
			
			
			
			
			The newLISP function 
pow  works like the Perl and Python function 
pow :
Code: Select all 
>>> pow(3, 0.33)
1.4369776521848516
>>> pow(-3, 0.33)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: negative number cannot be raised to a fractional power
>>> 
All use the Standard C Library function pow(a,b) using double floats.
 
		 
				
		
		 
	 
	
		
		
			
				
																			
								cameyo 							 
									
		Posts:  183 Joined:  Sun Mar 27, 2011 3:07 pmLocation:  Italy
				Contact: 
				
			 
				
		 
		
						
						
													
							
						
									
						Post 
					 
								by cameyo  Mon Oct 19, 2020 7:25 pm 
			
			
			
			
			Thanks for the explanation