Skip to content

Commit

Permalink
math dynop: Fix cmod_p_p_n* for NaN and Inf #1147
Browse files Browse the repository at this point in the history
Return a string in this case.
  • Loading branch information
Reini Urban committed Nov 22, 2014
1 parent df855de commit 1f93182
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -6,6 +6,7 @@
+ Added MEMORY_DEBUG tracing to --gc inf and ms2, added
GC validation to ms2.
+ Fix bignum.i_substract and i_multiply #1144
+ Fix cmod_p_p_n* math dynops for NaN and Inf #1147
+ Optimize printing of single numbers #828
- Build
+ Extend auto::infnan probe to other --floatval #1146
Expand Down
17 changes: 12 additions & 5 deletions src/dynoplibs/math.ops
Expand Up @@ -69,6 +69,8 @@ and defined with y == 0 is provided by the mod op.

If the denominator is zero, a 'Divide by zero' exception is thrown.

If the denominator is inf or nan, a wrong integer will be returned.

=cut

inline op cmod(out INT, in INT, in INT) {
Expand All @@ -93,7 +95,6 @@ inline op cmod(invar PMC, invar PMC, in INT) {
}

result = VTABLE_get_integer(interp, $2) % $3;

$1 = Parrot_pmc_new_init_int(interp, VTABLE_type(interp, $2), result);
}

Expand All @@ -109,7 +110,6 @@ inline op cmod(invar PMC, invar PMC, invar PMC) {
}

result = VTABLE_get_integer(interp, $2) % value;

$1 = Parrot_pmc_new_init_int(interp, VTABLE_type(interp, $2), result);
}

Expand Down Expand Up @@ -144,6 +144,9 @@ defined with y == 0 is provided by the mod op.

If the denominator is zero, a 'Divide by zero' exception is thrown.

If the denominator is inf or nan, the denominator will be returned
as String.

=cut

inline op cmod(out NUM, in NUM, in NUM) {
Expand All @@ -167,11 +170,15 @@ inline op cmod(invar PMC, invar PMC, in NUM) {
"Divide by zero");
goto ADDRESS(handler);
}

result = fmod(VTABLE_get_integer(interp, $2), value);

$1 = Parrot_pmc_new_init_int(interp,
VTABLE_type(interp, $2), (INTVAL)result);
if (PARROT_FLOATVAL_IS_INF_OR_NAN(result)) {
$1 = Parrot_pmc_new(interp, enum_class_String);
VTABLE_set_number_native(interp, $1, result);
}
else
$1 = Parrot_pmc_new_init_int(interp,
VTABLE_type(interp, $2), (INTVAL)result);
}

=back
Expand Down
3 changes: 1 addition & 2 deletions t/dynoplibs/math.t
Expand Up @@ -569,8 +569,7 @@ CODE
$P2 = 1
$N0 = 'NaN'
cmod $P1, $P2, $N0
#is($P1, 'NaN', 'cmod with Float and Integer PMCs and NaN')
todo(0, 'cmod with Float and Integer PMCs and NaN', 'cmod does not play nicely with PMCs and NaN')
is($P1, 'NaN', 'cmod with Float and Integer PMCs and NaN')
.end

# Local Variables:
Expand Down

0 comments on commit 1f93182

Please sign in to comment.