Issue #6044 has been reported by Marc-Andre Lafortune.

----------------------------------------
Bug #6044: Float#% bug in cornercases
https://bugs.ruby-lang.org/issues/6044

Author: Marc-Andre Lafortune
Status: Open
Priority: Normal
Assignee: Marc-Andre Lafortune
Category: core
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2012-02-16 trunk 34633) [x86_64-darwin10.8.0] 


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:
* consistent for different calling methods
* consistent accross platforms
* consistent with 4 % Float::INFINITY
* consistent with the IEEE definition of fmod (see http://pubs.opengroup.org/onlinepubs/007904975/functions/fmod.html )

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é


-- 
http://bugs.ruby-lang.org/