Yes I have printed @den1 and @den2 but both of them are not same. even
than I face the same problem when I tried to round @answer.
If I print @answer without rounding I am not getting the error and
getting a Number with long floating point Which is not required for me.
OK. Let’s simplify. Can you show the minimal piece of code that
produces the error. Like:
a = ?
b = ?
coeff = [?,?]
num = ?
den1 = coeff.first * Math::log10(a)
den2 = coeff.last * Math::log10(b)
p den1
p den2
answer = num/(den1-den2)
p answer
answer = (answer*100).round/100.to_f
Can you assign some example values to the variables (where I placed
the ?) from your program, run this and show us the output?
BTW, I’m not sure you need instance variables (variables starting with
@). Unless you are actually inside an instance of a class and you need
to keep all those values around.
In that case @num must be Infinity (or -Infinity). Possibly @a or @b
are 0 and so the logarithms you are calling earlier generate
-Infinity. Either way, as Jesus says the simplest thing is to just
print out all the intermediate variables until you see what’s wrong.
Apologies, I didn’t read your second paragraph closely enough. If your
number is above the Float maximum limit it will also die with this error
(so not necessarily Infinity, but a large number):
Yes I have printed @den1 and @den2 but both of them are not same.
even
than I face the same problem when I tried to round @answer.
If I print @answer without rounding I am not getting the error and
getting a Number with long floating point Which is not required for
me.
Raj
In that case @num must be Infinity (or -Infinity). Possibly @a or @b
are 0 and so the logarithms you are calling earlier generate -Infinity.
Either way, as Jesus says the simplest thing is to just print out all
the intermediate variables until you see what’s wrong.
In that case @num must be Infinity (or -Infinity). Possibly @a or @b
are 0 and so the logarithms you are calling earlier generate
-Infinity. Either way, as Jesus says the simplest thing is to just
print out all the intermediate variables until you see what’s wrong.
Apologies, I didn’t read your second paragraph closely enough. If your
number is above the Float maximum limit it will also die with this error
(so not necessarily Infinity, but a large number):