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

Both sides previous revision Previous revision
Next revision
Previous revision
gams:difference_between_the_-operator_and_the_power_function [2008/04/01 15:09]
support
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 ​(''​power(x)'' ​or ''​sqr(x)''​) the exponent ​must be an integer, which is not required if you uses the %%**%% operator. %%x**2%% is a a real power evaluated as exp(2*log(x)).+The power function ''​power(x,y)'' ​is an integer power and thus the exponent ​''​y''​ must be an integer. ​
  
-However, with the %%**%% operator ​the exponent ​must be a positive number to avoid an compilation ​error. So: +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 10: Line 10:
 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 17: 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.1207055397.txt.gz ยท Last modified: 2008/04/01 15:09 by support