Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Exponentiation
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==In programming languages== [[Programming language]]s generally express exponentiation either as an infix [[operator (computer programming)|operator]] or as a function application, as they do not support superscripts. The most common operator symbol for exponentiation is the [[caret]] (<code>^</code>). The [[ASCII#1963|original version of ASCII]] included an uparrow symbol (<code>β</code>), intended for exponentiation, but this was [[caret#History|replaced by the caret]] in 1967, so the caret became usual in programming languages.<ref>{{cite book|author=Richard Gillam|title=Unicode Demystified: A Practical Programmer's Guide to the Encoding Standard|year=2003|isbn=0201700522|page=33|publisher=Addison-Wesley Professional }}</ref> The notations include: * <code>x ^ y</code>: [[AWK]], [[BASIC]], [[J programming language|J]], [[MATLAB]], [[Wolfram Language]] ([[Wolfram Mathematica|Mathematica]]), [[R (programming language)|R]], [[Microsoft Excel]], [[Analytica (software)|Analytica]], [[TeX]] (and its derivatives), [[TI-BASIC]], [[bc programming language|bc]] (for integer exponents), [[Haskell (programming language)|Haskell]] (for nonnegative integer exponents), [[Lua (programming language)|Lua]], and most [[computer algebra system]]s. * <code>x ** y</code>. The [[Fortran]] character set did not include lowercase characters or punctuation symbols other than <code>+-*/()&=.,'</code> and so used <code>**</code> for exponentiation<ref name="Sayre_1956"/><ref>{{citation|author1=Brice Carnahan|author2=James O. Wilkes|title=Introduction to Digital Computing and FORTRAN IV with MTS Applications|year=1968|pages=2-2, 2-6}}</ref> (the initial version used <code>a xx b</code> instead.<ref name="Backus_1954"/>). Many other languages followed suit: [[Ada (programming language)|Ada]], [[Z shell]], [[KornShell]], [[Bash (Unix shell)|Bash]], [[COBOL]], [[CoffeeScript]], [[Fortran]], [[FoxPro 2|FoxPro]], [[Gnuplot]], [[Apache Groovy|Groovy]], [[JavaScript]], [[OCaml]], [[Object REXX|ooRexx]], [[F Sharp (programming language)|F#]], [[Perl]], [[PHP]], [[PL/I]], [[Python (programming language)|Python]], [[Rexx]], [[Ruby (programming language)|Ruby]], [[SAS programming language|SAS]], [[Seed7]], [[Tcl]], [[ABAP]], [[Mercury (programming language)|Mercury]], Haskell (for floating-point exponents), [[Turing (programming language)|Turing]], and [[VHDL]]. * <code>x β y</code>: [[Algol programming language|Algol Reference language]], [[Commodore BASIC]], [[TRS-80 Level II BASIC|TRS-80 Level II/III BASIC]].<ref name="InfoWorld_1982">{{cite news |title=BASCOM - A BASIC compiler for TRS-80 I and II |author-last=Daneliuk |author-first=Timothy "Tim" A. |date=1982-08-09 |newspaper=[[InfoWorld]] |series=Software Reviews |publisher=[[Popular Computing, Inc.]] |volume=4 |number=31 |pages=41β42 |url=https://books.google.com/books?id=NDAEAAAAMBAJ&pg=PA42 |access-date=2020-02-06 |url-status=live |archive-url=https://web.archive.org/web/20200207104336/https://books.google.de/books?id=NDAEAAAAMBAJ&pg=PA42&focus=viewport#v=onepage&q=TRS-80%20exponention |archive-date=2020-02-07}}</ref><ref name="80Micro_1983">{{cite journal |title=80 Contents |journal=[[80 Micro]] |publisher=[[1001001, Inc.]] |issn=0744-7868 |date=October 1983 |issue=45 |page=5 |url=https://archive.org/details/80-microcomputing-magazine-1983-10 |access-date=2020-02-06}}</ref> * <code>x ^^ y</code>: Haskell (for fractional base, integer exponents), [[D (programming language)|D]]. * <code>xβy</code>: [[APL (programming language)|APL]]. In most programming languages with an infix exponentiation operator, it is [[operator associativity|right-associative]], that is, <code>a^b^c</code> is interpreted as <code>a^(b^c)</code>.<ref>{{cite book|author=Robert W. Sebesta|title=Concepts of Programming Languages|year=2010|isbn=978-0136073475|pages=130, 324|publisher=Addison-Wesley }}</ref> This is because <code>(a^b)^c</code> is equal to <code>a^(b*c)</code> and thus not as useful. In some languages, it is left-associative, notably in [[Algol]], [[MATLAB]], and the [[Microsoft Office Excel|Microsoft Excel]] formula language. Other programming languages use functional notation: * <code>(expt x y)</code>: [[Common Lisp]]. * <code>pown x y</code>: [[F Sharp (programming language)|F#]] (for integer base, integer exponent). Still others only provide exponentiation as part of standard [[library (computing)|libraries]]: * <code>pow(x, y)</code>: [[C (programming language)|C]], [[C++]] (in <code>math</code> library). * <code>Math.Pow(x, y)</code>: [[C Sharp (programming language)|C#]]. * <code>math:pow(X, Y)</code>: [[Erlang (programming language)|Erlang]]. * <code>Math.pow(x, y)</code>: [[Java (programming language)|Java]]. * <code>[Math]::Pow(x, y)</code>: [[PowerShell]]. In some [[Type system|statically typed]] languages that prioritize [[type safety]] such as [[Rust (programming language)|Rust]], exponentiation is performed via a multitude of methods: * <code>x.pow(y)</code> for <code>x</code> and <code>y</code> as integers * <code>x.powf(y)</code> for <code>x</code> and <code>y</code> as floating-point numbers * <code>x.powi(y)</code> for <code>x</code> as a float and <code>y</code> as an integer
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)