/
infinity.t
86 lines (68 loc) · 2.24 KB
/
infinity.t
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
74
75
76
77
78
79
80
81
82
83
84
85
86
use v6;
use Test;
plan 21;
# L<S02/"Infinity and C<NaN>" /Perl 6 by default makes standard IEEE floating point concepts visible>
{
my $x = Inf;
ok( $x == Inf , 'numeric equal');
ok( $x eq 'Inf', 'string equal');
}
{
my $x = -Inf;
ok( $x == -Inf, 'negative numeric equal' );
ok( $x eq '-Inf', 'negative string equal' );
}
#?rakudo skip 'integer Inf RT #124451'
{
my $x = Inf.Int;
ok( $x == Inf, 'int numeric equal' );
ok( $x eq 'Inf', 'int string equal' );
}
#?rakudo skip 'integer Inf RT #124452'
{
my $x = ( -Inf ).Int;
ok( $x == -Inf, 'int numeric equal' );
ok( $x eq '-Inf', 'int string equal' );
}
# Inf should == Inf. Additionally, Inf's stringification (~Inf), "Inf", should
# eq to the stringification of other Infs.
# Thus:
# Inf == Inf # true
# and:
# Inf eq Inf # same as
# ~Inf eq ~Inf # true
ok truncate(Inf) ~~ Inf, 'truncate(Inf) ~~ Inf';
# RT #124453
{
throws-like { Inf.Int }, X::Numeric::CannotConvert,
'attempting to convert Inf to Int throws';
throws-like { (-Inf).Int }, X::Numeric::CannotConvert,
'attempting to convert Inf to Int throws';
throws-like { ∞.Int }, X::Numeric::CannotConvert,
'attempting to convert ∞ to Int throws';
throws-like { (-∞).Int }, X::Numeric::CannotConvert,
'attempting to convert -∞ to Int throws';
throws-like { NaN.Int }, X::Numeric::CannotConvert,
'attempting to convert NaN to Int throws';
}
# RT #70730
{
ok ( rand * Inf ) === Inf, 'multiply rand by Inf without maximum recursion depth exceeded';
}
{
#RT #126990
throws-like { my Int $x = Inf }, X::TypeCheck::Assignment,
:got(Inf), :expected(Int),
'trying to assign Inf to Int gives a helpful error';
my Num $x = Inf;
is $x, Inf, 'assigning Inf to Num works without errors';
}
{ # RT #129915
is-deeply -Inf², -Inf, '-Inf² follows mathematical order of operations';
is-deeply -∞², -Inf, '-∞² follows mathematical order of operations';
is-deeply −Inf², -Inf,
'−Inf² follows mathematical order of operations (U+2212 minus)';
is-deeply −∞², -Inf,
'−∞² follows mathematical order of operations (U+2212 minus)';
}
# vim: ft=perl6