Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 74 lines (58 sloc) 2.329 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
use v6;
use Test;
plan 72;

# L<S32::Numeric/Numeric/"=item exp">

=begin pod

Basic tests for the exp() builtin

=end pod

# SHOULD: test method forms of exp as well.

my $e_to_the_fifth = 5497075/37039;
my $pi = 312689/99532;

{
    is_approx(5.exp, $e_to_the_fifth, '5.exp == e to the fifth');
    is_approx(5.Rat.exp, $e_to_the_fifth, '5.Rat.exp == e to the fifth');
    is_approx(5.Num.exp, $e_to_the_fifth, '5.Num.exp == e to the fifth');
    is_approx(0.exp, 1, '0.exp == 1');

    is_approx((1i*$pi).exp, -1, '(i pi).exp == -1');
    is_approx((-1i*$pi).exp, -1, '(-i pi).exp == -1');

    #?pugs 7 todo
    is_approx(5.exp(2), 32, '5.exp(2) == 32');
    is_approx(5.Rat.exp(2), 32, '5.Rat.exp == 32');
    is_approx(5.Num.exp(2), 32, '5.Num.exp == 32');
    is_approx(0.exp(2), 1, '0.exp(2) == 1');
 
    is_approx((1i*$pi).exp(2), 2 ** (1i*$pi), '(i pi).exp(2) == 2 ** (1i*$pi)');
    is_approx((-1i*$pi).exp(2), 2 ** (-1i*$pi), '(-i pi).exp(2) == 2 ** (-1i*$pi)');
    is_approx(2.exp(1i*$pi), (1i*$pi) ** 2, '(2).exp(i pi) == (1i*$pi) ** 2');
}

is_approx(exp(5), $e_to_the_fifth, 'got the exponential of 5');
is_approx(exp(0), 1, 'exp(0) == 1');
is_approx(exp(-1), 0.3678794, '1/e is correct');
is(exp(Inf), Inf, 'exp(Inf) == Inf');
is(exp(-Inf), 0, 'exp(-Inf) == 0');
is(exp(NaN), NaN, 'exp(NaN) == NaN');
is_approx(exp(log(100)),100, 'e^(log(100))=100');

is_approx((1i*$pi).exp, -1, '(i $pi).exp == -1');
is_approx(exp(1i*$pi), -1, 'exp(i $pi) == -1');
is_approx(exp(-1i*$pi), -1, 'exp(-i $pi) == -1');

#?pugs 3 todo
is_approx(exp(5, 2), 32, 'got 32');
is_approx(exp(0, 2), 1, 'exp(0, 2) == 1');
is_approx(exp(-1, 2), 1/2, '1/2 is correct');
is(exp(Inf, 2), Inf, 'exp(Inf) == Inf');
#?pugs todo
is(exp(-Inf, 2), 0, 'exp(-Inf) == 0');
is(exp(NaN, 2), NaN, 'exp(NaN) == NaN');
#?pugs skip 'log multi'
is_approx(exp(log(100, 2), 2),100, 'e^(log(100, 2), 2)=100');

#?pugs 2 todo
is_approx(exp(1i*$pi, 2), 2 ** (1i*$pi), 'exp(i $pi, 2) == 2 ** (1i*$pi)');
is_approx(exp(-1i*$pi, 2), 2 ** (-1i*$pi), 'exp(-i $pi, 2) == 2 ** (-1i*$pi)');

##?pugs skip '..'
{
for 1 .. 20 {
my $arg = 2.0 * $pi / $_;
is_approx(exp(1i * $arg), cos($arg) + 1i * sin($arg), 'ex$pi == cos + i sin No. ' ~ $_);
is_approx(exp(1i * $arg) * exp(-1i * $arg), 1, 'exp(ix) * exp(-ix) == 1 No. ' ~ $_);
    }
}
# vim: ft=perl6
Something went wrong with that request. Please try again.