"함수 power()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
13번째 줄: 13번째 줄:
==C==
==C==
{{참고|C언어 pow()}}
{{참고|C언어 pow()}}
<source lang='c'>
<syntaxhighlight lang='c'>
#include <stdio.h>
#include <stdio.h>
#include <math.h>
#include <math.h>
24번째 줄: 24번째 줄:
     // 81
     // 81
}
}
</source>
</syntaxhighlight>


==Excel==
==Excel==
[[category: Excel]]
[[category: Excel]]
<source lang='php'>
<syntaxhighlight lang='php'>
=POWER(2,-3)
=POWER(2,-3)
// 0.125
// 0.125
=POWER(3,4)
=POWER(3,4)
// 81
// 81
</source>
</syntaxhighlight>


==Java==
==Java==
[[분류: Java]]
[[분류: Java]]
{{참고|자바 pow()}}
{{참고|자바 pow()}}
<source lang='Java'>
<syntaxhighlight lang='Java'>
public class MyClass {
public class MyClass {
     public static void main(String args[]) {
     public static void main(String args[]) {
48번째 줄: 48번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[category:JavaScript]]
[[category:JavaScript]]
<source lang='JavaScript'>
<syntaxhighlight lang='JavaScript'>
console.log( Math.pow(3,2) ); // 9
console.log( Math.pow(3,2) ); // 9
</source>
</syntaxhighlight>


==Perl==
==Perl==
[[category:Perl]]
[[category:Perl]]
<source lang='perl'>
<syntaxhighlight lang='perl'>
print 2**-3;
print 2**-3;
# 0.125
# 0.125
print 3**4;
print 3**4;
# 81
# 81
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
{{참고|PHP pow()}}
{{참고|PHP pow()}}
<source lang='php'>
<syntaxhighlight lang='php'>
var_dump( pow(2, -3) );
var_dump( pow(2, -3) );
# float(0.125)
# float(0.125)
var_dump( pow(3, 4) );
var_dump( pow(3, 4) );
# int(81)
# int(81)
</source>
</syntaxhighlight>


==Python==
==Python==
[[category: python]]
[[category: python]]
<source lang='python'>
<syntaxhighlight lang='python'>
print(2**-3)
print(2**-3)
# 0.125
# 0.125
print(3**4)
print(3**4)
# 81
# 81
</source>
</syntaxhighlight>
<source lang='python'>
<syntaxhighlight lang='python'>
print(pow(2,-3))
print(pow(2,-3))
# 0.125
# 0.125
print(pow(3,4))
print(pow(3,4))
# 81
# 81
</source>
</syntaxhighlight>


==Ruby==
==Ruby==
[[category: Ruby]]
[[category: Ruby]]
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
puts 2**-3
puts 2**-3
# 1/8
# 1/8
puts 3**4
puts 3**4
# 81
# 81
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:33 판

  다른 뜻에 대해서는 전력 문서를 참조하십시오.
  다른 뜻에 대해서는 power 문서를 참조하십시오.

1 개요

power
pow
**
  • Returns base raised to the power of exp.
  • test set
power(2, -3) → 0.125
power(3, 4) → 81

2 C

C
Copy
#include <stdio.h>
#include <math.h>
int main() {
    printf("%f\n", pow(2,-3));
    // 0.125000
    printf("%f\n", pow(3,4));
    // 81.000000
    printf("%d\n", (int)pow(3,4));
    // 81
}

3 Excel

PHP
Copy
=POWER(2,-3)
// 0.125
=POWER(3,4)
// 81

4 Java

Java
Copy
public class MyClass {
    public static void main(String args[]) {
        System.out.println( Math.pow(2, -3) ); // 0.125
        System.out.println( Math.pow(3, 0) ); // 1.0
        System.out.println( Math.pow(3, 1) ); // 3.0
        System.out.println( Math.pow(3, 2) ); // 9.0
        System.out.println( Math.pow(3, 4) ); // 81.0
    }
}

5 JavaScript

JavaScript
Copy
console.log( Math.pow(3,2) ); // 9

6 Perl

Perl
Copy
print 2**-3;
# 0.125
print 3**4;
# 81

7 PHP

PHP
Copy
var_dump( pow(2, -3) );
# float(0.125)
var_dump( pow(3, 4) );
# int(81)

8 Python

Python
Copy
print(2**-3)
# 0.125
print(3**4)
# 81
Python
Copy
print(pow(2,-3))
# 0.125
print(pow(3,4))
# 81

9 Ruby

Ruby
Copy
puts 2**-3
# 1/8
puts 3**4
# 81

10 같이 보기