Help us understand the problem. What is going on with this article?

いろんな言語でexp(log(0))

More than 3 years have passed since last update.

数学的な定義はともかく、エンジニア的にはおそらく、

\exp(\log(0))=0

であってほしいところですね。

JavaScript (Node.js 7.0.0)

$ node
> Math.exp(Math.log(0))
0

Python (Python 3.5.2)

$ python
Python 3.5.2 (default, Jul 21 2016, 02:38:09)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.exp(math.log(0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error

Ruby (Ruby 2.3.0, irb 0.9.6)

$ irb
irb(main):001:0> Math.exp(Math.log(0))
=> 0.0

Perl (Perl 5.18.2)

$ perl -le 'print exp(log(0))'
Can't take log of 0 at -e line 1.

Perl6 (Perl 6.c, Rakudo Star 2016.10)

$ perl6 -e 'say exp(log(0))'
0

$ perl6 -e 'say 0.log.exp'
0

Awk (Awk 4.0.1)

$ awk "BEGIN {print exp(log(0))}"
0

PHP (PHP 5.5.9-1)

$ php -r 'echo exp(log(0));'
0

C (GCC 4.8.4, glibc 2.19)

$ cat <<EOF > explog.c
> #include <stdio.h>
> #include <math.h>
> int main() {
>   printf("%f", exp(log(0)));
>   return 0;
> }
> EOF
$ gcc explog.c -o explog -lm
$ ./explog
0.000000

Java (OpenJDK 1.7.0_111)

$ cat <<EOF > explog.java
> import java.io.*;
>
> class explog {
>   public static void main (String[] args) {
>     System.out.println(Math.exp(Math.log(0)));
>   }
> }
> EOF
$ javac explog.java
$ java explog
0.0

Julia (Julia 0.5.0)

$ julia -e 'println(exp(log(0)))'
0.0

結果

言語 結果
JavaScript 0
Python エラー
Ruby 0.0
Perl エラー
Perl6 0
Awk 0
PHP 0
C 0.0
Java 0.0
Julia 0.0

言語の追加歓迎。

hakatashi
はい。そうです。
https://hakatashi.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away