Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0ae89dc771cf
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2c164e5b9233
Choose a head ref
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on May 30, 2015

  1. Copy the full SHA
    8681c49 View commit details
  2. Remove tags

    jsyeo committed May 30, 2015
    Copy the full SHA
    c1c2de0 View commit details
  3. Merge pull request #3417 from jsyeo/jsyeo-next-prev-float

    Implement Float#next_float Float#prev_float
    brixen committed May 30, 2015
    Copy the full SHA
    2c164e5 View commit details
Showing with 28 additions and 14 deletions.
  1. +28 −0 kernel/common/float.rb
  2. +0 −7 spec/tags/ruby/core/float/next_float_tags.txt
  3. +0 −7 spec/tags/ruby/core/float/prev_float_tags.txt
28 changes: 28 additions & 0 deletions kernel/common/float.rb
Original file line number Diff line number Diff line change
@@ -285,4 +285,32 @@ def floor
return int if self > 0 or self == int
return int - 1
end

def next_float
return NAN if self.nan?
return -MAX if self == -INFINITY
return INFINITY if self == MAX
return Math.ldexp(0.5, MIN_EXP - MANT_DIG + 1) if self.zero?

frac, exp = Math.frexp self

if frac == -0.5
frac *= 2
exp -= 1
end

smallest_frac = EPSILON / 2
smallest_frac = Math.ldexp(smallest_frac, MIN_EXP - exp) if exp < MIN_EXP

result_frac = frac + smallest_frac

return -0.0 if result_frac.zero? && frac < 0
return 0.0 if result_frac.zero? && frac > 0

return Math.ldexp result_frac, exp
end

def prev_float
return -(-self).next_float
end
end
7 changes: 0 additions & 7 deletions spec/tags/ruby/core/float/next_float_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/tags/ruby/core/float/prev_float_tags.txt

This file was deleted.