Method: PropCheck::Generators.float

Defined in:
lib/prop_check/generators.rb

.floatObject

Generates floating-point numbers Will generate NaN, Infinity, -Infinity, as well as Float::EPSILON, Float::MAX, Float::MIN, 0.0.next_float, 0.0.prev_float, to test the handling of floating-point edge cases. Approx. 1/50 generated numbers is a special one.

Shrinks to smaller, real floats.

>> Generators.float().sample(10, size: 10, rng: Random.new(42))
>>  Generators.float().sample(10, size: 10, rng: Random.new(4))
=> [-8.0, 2.0, 2.7142857142857144, -4.0, -10.2, -6.666666666666667, -Float::INFINITY, -10.2, 2.1818181818181817, -6.2]

232
233
234
# File 'lib/prop_check/generators.rb', line 232

def float
  frequency(49 => real_float, 1 => one_of(*@@special_floats.map(&method(:constant))))
end