Exponentiation operator: Difference between revisions

Content deleted Content added
m →‎{{header|REXX}}: added/changed comments and whitespace, changed indentations.
PureFox (talk | contribs)
Added FreeBASIC
Line 928:
<pre>
1073741824 1.073742E+09
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0
 
' Note that 'base' is a keyword in FB, so we use 'base_' instead as a parameter
 
Function Pow Overload (base_ As Double, exponent As Integer) As Double
If exponent = 0.0 Then Return 1.0
If exponent = 1.0 Then Return base_
If exponent < 0.0 Then Return 1.0 / Pow(base_, -exponent)
Dim power As Double = base_
For i As Integer = 2 To exponent
power *= base_
Next
Return power
End Function
 
Function Pow Overload(base_ As Integer, exponent As Integer) As Double
Return Pow(CDbl(base_), exponent)
End Function
 
' check results of these functions using FB's built in '^' operator
Print "Pow(2, 2) = "; Pow(2, 2)
Print "Pow(2.5, 2) = "; Pow(2.5, 2)
Print "Pow(2, -3) = "; Pow(2, -3)
Print "Pow(1.78, 3) = "; Pow(1.78, 3)
Print
Print "2 ^ 2 = "; 2 ^ 2
Print "2.5 ^ 2 = "; 2.5 ^ 2
Print "2 ^ -3 = "; 2 ^ -3
Print "1.78 ^ 3 = "; 1.78 ^ 3
Print
Print "Press any key to quit"
Sleep</lang>
 
{{out}}
<pre>
Pow(2, 2) = 4
Pow(2.5, 2) = 6.25
Pow(2, -3) = 0.125
Pow(1.78, 3) = 5.639752000000001
 
2 ^ 2 = 4
2.5 ^ 2 = 6.25
2 ^ -3 = 0.125
1.78 ^ 3 = 5.639752000000001
</pre>