User Tools

Site Tools


gams:difference_between_the_-operator_and_the_power_function

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gams:difference_between_the_-operator_and_the_power_function [2007/05/25 08:38]
127.0.0.1 external edit
gams:difference_between_the_-operator_and_the_power_function [2008/07/26 05:49] (current)
support
Line 1: Line 1:
 ====== What is the difference between the ** operator and the power function? ====== ====== What is the difference between the ** operator and the power function? ======
    
-If you use the power function the exponent must be an integer, which is not required ​if you uses the %%**%% operator. ​However, with the %%**%% ​operator the exponent ​must be a positive number to avoid an compilation ​error. So: +The power function ​''​power(x,​y)''​ is an integer power and thus the exponent ​''​y'' ​must be an integer.  
 + 
 +This is not required ​for the %%**%% operator. ​ %%x**y%% is a real power and gets evaluated as ''​exp(y * log(x))''​. The real power is not defined for a negative base (e.g. http://​www.cppreference.com/​stdmath/​pow.html) -  ''​x'' ​must be a positive number ​(or ''​y >= 0'',​ if  ''​x = 0''​) ​to avoid an execution ​error. So: 
 <​code>​ <​code>​
 scalar test;  scalar test; 
Line 7: Line 9:
 * note: this is not the same as -3**4,which will be treated as -(3**4) ​ * note: this is not the same as -3**4,which will be treated as -(3**4) ​
 display test;  display test; 
-</ code> +</​code>​ 
-will give you an error: ​+will return ​an error: ​
 <​code>​ <​code>​
 **** Exec Error at line 2: rPower: FUNC DOMAIN: x**y, x < 0 **** Exec Error at line 2: rPower: FUNC DOMAIN: x**y, x < 0
Line 15: Line 17:
 <​code>​ <​code>​
 scalar test;  scalar test; 
-test = power(3,​4); ​+test = power(-3,4); 
 display test;  display test; 
 </​code>​ </​code>​
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/difference_between_the_-operator_and_the_power_function.1180075138.txt.gz · Last modified: 2008/04/01 10:03 (external edit)