Project

General

Profile

Backport #6044

Float#% bug in cornercases

Added by marcandre (Marc-Andre Lafortune) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:42726]

Description

On my platform, current behavior is:

4.0 % Float::INFINITY # => NaN
4.0.send :%, Float::INFINITY # => 4.0

-0.0 % 42 # => 0.0
-0.0.send(:%, 42) # => -0.0

On some platforms, these might return NaN and 0.0 in all cases.

My proposed behavior is to return 4.0 and -0.0 on all cases and on all platforms.

I'm tempted to assume it is clear that this is bug and that my proposed behavior is the right solution, but let me use my guidelines:

Proposed behavior passes my "strict superiority test" as it is clearly more consistent:

It is also more intuitive and useful, since:

any_small_number % any_big_number == any_small_number

Current behavior passes the "clear defect test" as it is platform dependent (when it can reasonable be platfom independent). I'll add to the list of "clear defect" criteria the fact that calling an operator directly doesn't yield the same result as using #send.

The proposed solution fails my "straightforward" test as the proposed behavior contradicts part of the documentation which states "x.modulo(y) means x-y*(x/y).floor".

Any objection for me to commit this?

Thanks

Marc-André


Files

fixmodulo.patch (2.7 KB) fixmodulo.patch marcandre (Marc-Andre Lafortune), 02/18/2012 09:26 AM

Also available in: Atom PDF