/
phpfloat.pmc
207 lines (141 loc) · 3.16 KB
/
phpfloat.pmc
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Copyright (C) 2008, The Perl Foundation.
=head1 NAME
src/pmc/phpfloat.pmc - PHP Float
=head1 DESCRIPTION
=head2 Methods
=over 4
=cut
*/
#include "php_private.h"
pmclass PhpFloat
extends Float
provides scalar
provides float
dynpmc
group pipp_group
hll PHP
maps Float {
/*
=item C<STRING* name()>
Return the string 'double'.
=cut
*/
STRING* name() {
return Parrot_str_new_constant(INTERP, "double");
}
/*
=back
=head2 non-Vtable Methods
=over 4
=item C<STRING* serialize()>
Return a representation of this float in the same format as PHP's serialize function.
=cut
*/
METHOD STRING* serialize() {
STRING *serialized;
INTVAL zero_index = -1;
/* PHP's serialized floats stringify the exact value stored rather than
* just the significant digits. */
serialized = Parrot_str_format_data(INTERP, "%.*f", 100, VTABLE_get_number(INTERP, SELF));
while (string_ord(INTERP, serialized, zero_index - 1) == '0')
zero_index--;
serialized = Parrot_str_chopn(INTERP, serialized, 0 - zero_index);
serialized = Parrot_str_format_data(INTERP, "f:%Ss;", serialized);
RETURN(STRING *serialized);
}
/*
=back
=head2 Specific Methods
=over 4
=item C<PMC* acosh()>
=cut
*/
METHOD acosh() {
PMC * const d = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
SET_ATTR_fv(INTERP, d, acosh(SELF.get_number()));
RETURN(PMC *d);
}
/*
=item C<PMC* asinh()>
=cut
*/
METHOD asinh() {
PMC * const d = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
SET_ATTR_fv(INTERP, d, asinh(SELF.get_number()));
RETURN(PMC *d);
}
/*
=item C<PMC* atanh()>
=cut
*/
METHOD atanh() {
PMC * const d = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
SET_ATTR_fv(INTERP, d, atanh(SELF.get_number()));
RETURN(PMC *d);
}
/*
=item C<PMC* is_finite()>
=cut
*/
METHOD PMC* is_finite() {
PMC *retval = pmc_new(INTERP, dynpmc_PhpBoolean);
#if 1
FLOATVAL d = SELF.get_number();
INTVAL val = finite(d);
VTABLE_set_bool(INTERP, retval, val);
#else
VTABLE_set_bool(INTERP, retval, 0);
#endif
RETURN(PMC *retval);
}
/*
=item C<PMC* is_infinite()>
=cut
*/
METHOD PMC* is_infinite() {
PMC *retval = pmc_new(INTERP, dynpmc_PhpBoolean);
#if 1
FLOATVAL d = SELF.get_number();
INTVAL val = isinf(d);
VTABLE_set_bool(INTERP, retval, val);
#else
VTABLE_set_bool(INTERP, retval, 0);
#endif
RETURN(PMC *retval);
}
/*
=item C<PMC* is_nan()>
=cut
*/
METHOD PMC* is_nan() {
PMC *retval = pmc_new(INTERP, dynpmc_PhpBoolean);
#if 1
FLOATVAL d = SELF.get_number();
INTVAL val = isnan(d);
VTABLE_set_bool(INTERP, retval, val);
#else
VTABLE_set_bool(INTERP, retval, 0);
#endif
RETURN(PMC *retval);
}
/*
=item C<PMC* to_number()>
=cut
*/
METHOD PMC* to_number() {
RETURN(PMC *SELF);
}
}
/*
=back
=head1 AUTHORS
Francois Perrad.
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/