[Home]
HomePage RecentChanges Frequently Asked Questions

exponent

Warning!

The use of gawkisms will prevent the script from running correctly on systems that use a traditional awk interpreter.

The doublestar exponent operator is not available in traditional implementations

  • Traditional awk implementations do not provide an exponent arithmetic operator. The [[doublestar?]] symbol used here for arithmetic exponential operations is a gawkism and will not work in traditional awk.

The doublestar gawkism

  • The [[doublestar?]] gawkism acts as a dyadic exponent operator. It returns the [[value?]] given as a left [[operand?]] to the power of the right [[operand?]]. The [[operand?]]s can be [[floating_poin?]]t values, producing a [[floating_point?]] value:
print (4 ** 3) # 64 (4 to the power of 3)

Precedence

print (2 * 4 ** 3) # 128 the exponent has a higher precedence than multiplication

Exponent Combination Assignment Operator

  • The exponent [[combination_assignment_operator?]] gawkism represented by a [[starstarequals?]] trigraph, can also be used to perform an exponent calculation:
value **= 3 # value = value ** 3

Edit this page View other revisions Administration
Last edited 2012年03月20日 07:33 UTC by g0pher (diff)

Powered by sdf Creative Commons License <pierre.gaston+awk@gmail.com>

Awk Wiki by #awk is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

AltStyle によって変換されたページ (->オリジナル) /