ruby - Why does Math.Log crash only inside my for loop? -


i have below code

a = 1.0 b = 0.20 n = 8.0 in 1..total   t = maxt * rand   x = * math.cos(t) / (math.log(b*math.tan(t/(2*n))))   y = * math.sin(t) / (math.log(b*math.tan(t/(2*n)))) end 

if comment out loop executes fine , produces 1 of results want. if don't comment out loop, generates below. newbie ruby , curious why breaks when loop present.

rubyfile.rb:22:in `log': numerical argument out of domain - log (errno::edom)     rubyfile.rb:22     rubyfile.rb:20:in `each'     rubyfile.rb:20 

math.log represents logarithm function, undefined negative numbers. math.tan, however, represents tangent function, can return negative numbers. so, if math.tan comes out negative number, math.log tell argument "out of domain", meaning there no logarithm number.

i'm betting fact input random means that, when loop, far more error if run script once. if remove loop run script multiple times, bet you'd error eventually.

find out why math involves negative numbers when shouldn't, , you're go :)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -