All Forums Database
pjozwiak 7 posts Joined 05/11
23 Mar 2015
Bug in exponentiate ** operator precedence and associativity ?

Consider below query:

SELECT 2**3**4

as a result teradata returns value of expression 4096. This means that provided expression was calculated in this way:

//Teradata left associative (probably wrong):
((2**3)**4) = 4,096

But this is wrong !
When expression contains operators with same precedence then normally expression is evaluated from left - to right. But exponentiate operator is evaluated from right to left.
This means that presented expression should be evaluated in this way:

//Google and Mathematical theory says that 2**3**4 is right associative
(2**(3**4)) = 2,417,851,639,229,260,000,000,000

Try to evaluated this expression in for ex. google. Expression is evaluated from right to left. Also wikipedia describes this problem in this articel: http://en.wikipedia.org/wiki/Operator_associativity in same way as google evaluates this kind of expressions saying that operator is right associative.
Why Teradata is evaluating this operator from left to right ? Is it just a bug or intended behaviour?

dnoeth 4628 posts Joined 11/04
23 Mar 2015

The manuals clearly specify the left-to-right order, so at least it's documented behaviour :-)
I tend to use brackets, so there's no gueass about order...
 
Btw, your expected result is wrong.
Google returns an approximate result, 2.4178516e+24, and (2**(3**4)) is actually not 2,417,851,639,229,260,000,000,000 (Teradata returns FLOATs for exponentiation) but 2,417,851,639,229,258,349,412,352.
 
 
 

Dieter

You must sign in to leave a comment.