我有以下代码
A = 1.0
B = 0.20
N = 8.0
for i in 1..Total
t = Maxt * rand
x = A * Math.cos(t) / (Math.log(B*Math.tan(t/(2*N))))
y = A * Math.sin(t) / (Math.log(B*Math.tan(t/(2*N))))
end
如果我注释掉 For 循环,它可以正常执行并产生我想要的 1 个结果。如果我不注释掉 for 循环,它会生成以下内容。我是 Ruby 的新手,主要是好奇为什么它只在存在 for 循环时才会中断。
rubyfile.rb:22:in `log': Numerical argument out of domain - log (Errno::EDOM)
from rubyfile.rb:22
from rubyfile.rb:20:in `each'
from rubyfile.rb:20