Skip to content

Instantly share code, notes, and snippets.

@mustmodify
Last active August 29, 2015 14:11
Show Gist options
  • Save mustmodify/a68d131871be9af212ad to your computer and use it in GitHub Desktop.
Save mustmodify/a68d131871be9af212ad to your computer and use it in GitHub Desktop.
def gap_weight_for( age )
difference = (value_of(age) - patient_age).abs
( difference * 0.1 ) ** 1.07
end
intermittently results in:
in `**': #<Class:0x0000000a693110> can't be coerced into BigDecimal (TypeError)
def gap_weight_for( age )
difference = (value_of(age) - patient_age).abs
begin
( difference * 0.1 ) ** 1.07
rescue => ex
puts "#{difference.inspect} or #{(difference * 0.1).inspect} was a math problem."
end
end
results in:
#<BigDecimal:12a1b168,'0.45E2',9(27)> or #<BigDecimal:12a33e70,'0.45E1',18(36)> was a math problem.
@tries = 10000
@failures = []
@tries.times do |i|
begin
BigDecimal.new('2E0') ** 1.07
putc '.'
rescue
putc 'x'
@failures << i
end
end
puts "Failed #{@failures.size} times out of #{@tries.to_s} tries."
...................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x.....................................................................................................................................................................................................................................................................................................................................................................................................................x......................................................................................................................................................................................................................................................................
Failed 20 times out of 10000 times.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment