Skip to content

Commit

Permalink
Get fixnum_{min,max} from RbConfig::LIMITS when available
Browse files Browse the repository at this point in the history
It's better than guessing based on the pointer size if the
implementation provides it directly.
  • Loading branch information
XrXr committed Jul 24, 2024
1 parent 48524a4 commit f6f1350
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion spec/mspec/lib/mspec/helpers/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,24 @@ def min_long
# specs based on the relationship between values rather than specific
# values.
if PlatformGuard.standard? or PlatformGuard.implementation? :topaz
if PlatformGuard.c_long_size? 32
limits_available = begin
require 'rbconfig/sizeof'
defined?(RbConfig::LIMITS.[]) && ['FIXNUM_MAX', 'FIXNUM_MIN'].all? do |key|
Integer === RbConfig::LIMITS[key]
end
rescue LoadError
false
end

if limits_available
def fixnum_max
RbConfig::LIMITS['FIXNUM_MAX']
end

def fixnum_min
RbConfig::LIMITS['FIXNUM_MIN']
end
elsif PlatformGuard.c_long_size? 32
def fixnum_max
(2**30) - 1
end
Expand Down

0 comments on commit f6f1350

Please sign in to comment.