| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PPI::Token::Number::Exp; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
PPI::Token::Number::Exp - Token class for an exponential notation number |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$n = 1.0e-2; |
|
12
|
|
|
|
|
|
|
$n = 1e+2; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 INHERITANCE |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
PPI::Token::Number::Exp |
|
17
|
|
|
|
|
|
|
isa PPI::Token::Number::Float |
|
18
|
|
|
|
|
|
|
isa PPI::Token::Number |
|
19
|
|
|
|
|
|
|
isa PPI::Token |
|
20
|
|
|
|
|
|
|
isa PPI::Element |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
The C class is used for tokens that |
|
25
|
|
|
|
|
|
|
represent floating point numbers with exponential notation. |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 METHODS |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
|
30
|
|
|
|
|
|
|
|
|
31
|
65
|
|
|
65
|
|
463
|
use strict; |
|
|
65
|
|
|
|
|
129
|
|
|
|
65
|
|
|
|
|
2048
|
|
|
32
|
65
|
|
|
65
|
|
400
|
use PPI::Token::Number::Float (); |
|
|
65
|
|
|
|
|
126
|
|
|
|
65
|
|
|
|
|
33906
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our $VERSION = '1.277'; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our @ISA = "PPI::Token::Number::Float"; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 literal |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Return the numeric value of this token. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub literal { |
|
47
|
13
|
|
|
13
|
1
|
228
|
my $self = shift; |
|
48
|
13
|
50
|
|
|
|
42
|
return if $self->{_error}; |
|
49
|
13
|
|
|
|
|
39
|
my ($mantissa, $exponent) = split m/e/i, $self->_literal; |
|
50
|
13
|
|
|
|
|
33
|
my $neg = $mantissa =~ s/^\-//; |
|
51
|
13
|
|
|
|
|
25
|
$mantissa =~ s/^\./0./; |
|
52
|
13
|
|
|
|
|
26
|
$exponent =~ s/^\+//; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Must cast exponent as numeric type, due to string type '00' exponent |
|
55
|
|
|
|
|
|
|
# creating false positive condition in for() loop below, causing infinite loop |
|
56
|
13
|
|
|
|
|
46
|
$exponent += 0; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# This algorithm is reasonably close to the S_mulexp10() |
|
59
|
|
|
|
|
|
|
# algorithm from the Perl source code, so it should arrive |
|
60
|
|
|
|
|
|
|
# at the same answer as Perl most of the time. |
|
61
|
13
|
|
|
|
|
22
|
my $negpow = 0; |
|
62
|
13
|
100
|
|
|
|
46
|
if ($exponent < 0) { |
|
63
|
2
|
|
|
|
|
11
|
$negpow = 1; |
|
64
|
2
|
|
|
|
|
4
|
$exponent *= -1; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
13
|
|
|
|
|
18
|
my $result = 1; |
|
68
|
13
|
|
|
|
|
21
|
my $power = 10; |
|
69
|
13
|
|
|
|
|
32
|
for (my $bit = 1; $exponent; $bit = $bit << 1) { |
|
70
|
22
|
100
|
|
|
|
36
|
if ($exponent & $bit) { |
|
71
|
12
|
|
|
|
|
18
|
$exponent = $exponent ^ $bit; |
|
72
|
12
|
|
|
|
|
19
|
$result *= $power; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
22
|
|
|
|
|
48
|
$power *= $power; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
13
|
100
|
|
|
|
31
|
my $val = $neg ? 0 - $mantissa : $mantissa; |
|
78
|
13
|
100
|
|
|
|
51
|
return $negpow ? $val / $result : $val * $result; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
##################################################################### |
|
86
|
|
|
|
|
|
|
# Tokenizer Methods |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub __TOKENIZER__on_char { |
|
89
|
95
|
|
|
95
|
|
142
|
my $class = shift; |
|
90
|
95
|
|
|
|
|
119
|
my $t = shift; |
|
91
|
95
|
|
|
|
|
165
|
my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# To get here, the token must have already encountered an 'E' |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Allow underscores straight through |
|
96
|
95
|
100
|
|
|
|
193
|
return 1 if $char eq '_'; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# Allow digits |
|
99
|
86
|
100
|
|
|
|
253
|
return 1 if $char =~ /\d/o; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Start of exponent is special |
|
102
|
41
|
100
|
|
|
|
136
|
if ( $t->{token}->{content} =~ /e$/i ) { |
|
103
|
|
|
|
|
|
|
# Allow leading +/- in exponent |
|
104
|
16
|
50
|
66
|
|
|
98
|
return 1 if $char eq '-' || $char eq '+'; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Invalid character in exponent. Recover |
|
107
|
0
|
0
|
|
|
|
0
|
if ( $t->{token}->{content} =~ s/\.(e)$//i ) { |
|
108
|
0
|
|
|
|
|
0
|
my $word = $1; |
|
109
|
0
|
|
|
|
|
0
|
$t->{class} = $t->{token}->set_class('Number'); |
|
110
|
0
|
|
|
|
|
0
|
$t->_new_token('Operator', '.'); |
|
111
|
0
|
|
|
|
|
0
|
$t->_new_token('Word', $word); |
|
112
|
0
|
|
|
|
|
0
|
return $t->{class}->__TOKENIZER__on_char( $t ); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
else { |
|
115
|
0
|
|
|
|
|
0
|
$t->{token}->{_error} = "Illegal character in exponent '$char'"; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Doesn't fit a special case, or is after the end of the token |
|
120
|
|
|
|
|
|
|
# End of token. |
|
121
|
25
|
|
|
|
|
56
|
$t->_finalize_token->__TOKENIZER__on_char( $t ); |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=pod |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 SUPPORT |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
See the L in the main module. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Chris Dolan Ecdolan@cpan.orgE |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright 2006 Chris Dolan. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This program is free software; you can redistribute |
|
141
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
The full text of the license can be found in the |
|
144
|
|
|
|
|
|
|
LICENSE file included with this module. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |