Zero to the zero power: Difference between revisions
(→{{header|J}}: Add J) |
(→Tcl: Added implementation) |
||
Line 1: | Line 1: | ||
{{draft task}} |
{{draft task}} |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Show the results of raising zero to the zeroth power. |
Show the results of raising zero to the zeroth power. |
||
If your computer language objects to |
If your computer language objects to <code>0**0</code> at compile time, you may also try something like: |
||
<lang rexx>x = 0 |
<lang rexx>x = 0 |
||
y = 0 |
y = 0 |
||
z = x**y |
z = x**y |
||
··· show the result ···</lang> |
··· show the result ···</lang> |
||
Of course, use any symbols or notation that is supported in your computer language for exponentiation. |
Of course, use any symbols or notation that is supported in your computer language for exponentiation. |
||
;See also: |
;See also: |
||
* The Wiki entry: [ |
* The Wiki entry: [[wp:Exponentiation#Zero_to_the_power_of_zero|Zero to the power of zero]]. |
||
* The Wiki entry: [ |
* The Wiki entry: [[wp:Exponentiation#History_of_differing_points_of_view|History of differing points of view]]. |
||
* The |
* The MathWorld™ entry: [http://mathworld.wolfram.com/ExponentLaws.html exponent laws]. |
||
** Also, in the above MathWorld™ entry, see formula ('''9'''): <math>x^0=1</math>. |
|||
* The OEIS entry: [https://oeis.org/wiki/The_special_case_of_zero_to_the_zeroth_power The special case of zero to the zeroth power] |
* The OEIS entry: [https://oeis.org/wiki/The_special_case_of_zero_to_the_zeroth_power The special case of zero to the zeroth power] |
||
<br><br> |
|||
=={{header|C}}== |
=={{header|C}}== |
||
This example uses the standard pow function in the math library. 0^0 is given as 1. |
This example uses the standard <code>pow</code> function in the math library. 0^0 is given as 1. |
||
⚫ | |||
⚫ | |||
⚫ | |||
#include<stdio.h> |
#include<stdio.h> |
||
Line 139: | Line 132: | ||
</pre> |
</pre> |
||
using R4 |
|||
<lang rexx>∙∙∙ same program ∙∙∙</lang> |
<lang rexx>∙∙∙ same program ∙∙∙</lang> |
||
'''output''' |
'''output''' |
||
Line 148: | Line 141: | ||
Statement source: say '0 ** 0 (zero to the zeroth power) ───► ' 0**0 |
Statement source: say '0 ** 0 (zero to the zeroth power) ───► ' 0**0 |
||
Statement context: C:\ZERO_TO0.REX, procedure: ZERO_TO0 |
Statement context: C:\ZERO_TO0.REX, procedure: ZERO_TO0 |
||
</pre> |
</pre> |
||
using ROO |
|||
<lang rexx>∙∙∙ same program ∙∙∙</lang> |
<lang rexx>∙∙∙ same program ∙∙∙</lang> |
||
'''output''' |
'''output''' |
||
Line 161: | Line 153: | ||
Statement context: C:\ZERO_TO0.REX, procedure: ZERO_TO0 |
Statement context: C:\ZERO_TO0.REX, procedure: ZERO_TO0 |
||
</pre> |
</pre> |
||
=={{header|Tcl}}== |
|||
Interactively… |
|||
<lang tcl>% expr 0**0 |
|||
1 |
|||
% expr 0.0**0.0 |
|||
⚫ |
Revision as of 00:30, 21 March 2014
Some programming languages are not exactly consistent (with other programming languages) when raising zero to the zeroth power: .
- Task requirements
Show the results of raising zero to the zeroth power.
If your computer language objects to 0**0
at compile time, you may also try something like:
<lang rexx>x = 0
y = 0
z = x**y
··· show the result ···</lang>
Of course, use any symbols or notation that is supported in your computer language for exponentiation.
- See also
- The Wiki entry: Zero to the power of zero.
- The Wiki entry: History of differing points of view.
- The MathWorld™ entry: exponent laws.
- Also, in the above MathWorld™ entry, see formula (9): .
- The OEIS entry: The special case of zero to the zeroth power
C
This example uses the standard pow
function in the math library. 0^0 is given as 1.
<lang C>/*Abhishek Ghosh, 18th March 2014, Rotterdam*/
- include<stdio.h>
- include<math.h>
int main() { printf("0 ^ 0 = %f",pow(0,0)); return 0; } </lang>
- Output:
0 ^ 0 = 1.000000
D
<lang d>void main() {
import std.stdio, std.math, std.bigint, std.complex;
writeln("Int: ", 0 ^^ 0); writeln("Ulong: ", 0UL ^^ 0UL); writeln("Float: ", 0.0f ^^ 0.0f); writeln("Double: ", 0.0 ^^ 0.0); writeln("Real: ", 0.0L ^^ 0.0L); writeln("pow: ", pow(0, 0)); writeln("BigInt: ", 0.BigInt ^^ 0); writeln("Complex: ", complex(0.0, 0.0) ^^ 0);
}</lang>
- Output:
Int: 1 Ulong: 1 Float: 1 Double: 1 Real: 1 pow: 1 BigInt: 1 Complex: 1+0i
Go
Go does not have an exponentiation operator but has functions in the standard library for three types, float64, complex128, and big.Int. The functions for float64 and big.Int are documented to return 1. The function for complex128 does not have the special case documented. <lang go>package main
import (
"fmt" "math" "math/big" "math/cmplx"
)
func main() {
fmt.Println("float64: ", math.Pow(0, 0)) var b big.Int fmt.Println("big integer:", b.Exp(&b, &b, nil)) fmt.Println("complex: ", cmplx.Pow(0, 0))
}</lang>
- Output:
float64: 1 big integer: 1 complex: (0+0i)
J
<lang j> 0 ^ 0 1</lang>
Java
<lang java>System.out.println(Math.pow(0, 0));</lang>
- Output:
1.0
Perl 6
Translation of REXX.
<lang perl 6>say '0 ** 0 (zero to the zeroth power) ───► ', 0**0</lang>
- Output:
0 ** 0 (zero to the zeroth power) ───► 1
Python
<lang python>>>> from decimal import Decimal >>> from fractions import Fraction >>> for n in (Decimal(0), Fraction(0, 1), complex(0), float(0), int(0)): try: n1 = n**n except: n1 = '<Raised exception>' try: n2 = pow(n, n) except: n2 = '<Raised exception>' print('%8s: ** -> %r; pow -> %r' % (n.__class__.__name__, n1, n2))
Decimal: ** -> '<Raised exception>'; pow -> '<Raised exception>'
Fraction: ** -> Fraction(1, 1); pow -> Fraction(1, 1)
complex: ** -> (1+0j); pow -> (1+0j) float: ** -> 1.0; pow -> 1.0 int: ** -> 1; pow -> 1
>>> </lang>
REXX
using PC/REXX
using Personal REXX
using REGINA
<lang rexx>/*REXX program shows the results of raising zero to the zeroth power.*/
say '0 ** 0 (zero to the zeroth power) ───► ' 0**0</lang>
output
0 ** 0 (zero to the zeroth power) ───► 1
using R4 <lang rexx>∙∙∙ same program ∙∙∙</lang> output
Error 26 : Invalid whole number (SYNTAX) Information: 0 ** 0 is undefined Error occurred in statement# 2 Statement source: say '0 ** 0 (zero to the zeroth power) ───► ' 0**0 Statement context: C:\ZERO_TO0.REX, procedure: ZERO_TO0
using ROO <lang rexx>∙∙∙ same program ∙∙∙</lang> output
Error 26 : Invalid whole number (SYNTAX) Information: 0 ** 0 is undefined Error occurred in statement# 2 Statement source: say '0 ** 0 (zero to the zeroth power) ───► ' 0**0 Statement context: C:\ZERO_TO0.REX, procedure: ZERO_TO0
Tcl
Interactively… <lang tcl>% expr 0**0 1 % expr 0.0**0.0 1.0</lang>