TPK algorithm: Difference between revisions

Content deleted Content added
Maerics (talk | contribs)
Ruby version: Removed distracting begin/rescue block.
Line 75:
<source lang="ruby">
Array.new(11) { gets.to_i }.reverse.each do |x|
y = Math.sqrt(x.abs) + 5*x ** 3
begin
puts "#{x} #{(y>400) ? 'TOO LARGE' : y}"
y = Math.sqrt(x.abs) + 5*x ** 3
raise if y > 400
puts "#{x} #{y}"
rescue
puts "#{x} TOO LARGE"
end
end
</source>
 
Ruby handles numerical overflow by returning Infinity, which is greater than 400.
Ruby handles extremely large values very easily, even on 64-bit systems, so the possibility of an overflow in the above program would be slim.
 
==References==