0

I am using the math.log10() function to compute the percentage of damage coverage a character. The value is affected by the character's deff_toughness skill. The skill can range 0-20. Here is the code:

double percentage_damage_reduced = (Math.log10(deff_toughness/2 + 1));

Now, i know any logarythms dont exist for values = 0. Thats why i added a +1. If you visualize this graph for x[0,20] its values range aprox from 0 to 1. But for deff_toughness = [0,1,2,3], the output is 0. Any ideas why?

  • 5
    Is `deff_toughness` an `int` or a `double`? – Sweeper May 08 '20 at 08:42
  • Is and int, and i just read in the documentation log10 takes a double as a parameter. Could that be the problem? – Heavy Breathing Cat May 08 '20 at 08:44
  • Indeed (not exactly the parameter, but the calculation of the parameter value). Try `Math.log10(deff_toughness/2.0 + 1)`. – Andreas Fester May 08 '20 at 08:45
  • 5
    No, please read the duplicate target. `/ 2` is the problem. – Sweeper May 08 '20 at 08:45
  • This question is not a duplicate to the linked one. The linked one explains the reason why it works this way, however the question itself is different and could be useful to other people. – Vilmantas Baranauskas May 08 '20 at 08:48
  • 1
    Solved! It was the int to double conversion and some background calculation that was messing with deff_toughness's value. Thank you all very much! – Heavy Breathing Cat May 08 '20 at 08:57
  • @VilmantasBaranauskas Not sure if an answer of the form: *Change `2` to `2.0`* would be of any use to other people. The duplicate is enough guidance for anyone that has a similar problem IMO – Lino May 08 '20 at 09:02

0 Answers0