Check if a double is evenly divisible by another double in C?

前端 未结 7 2089
故里飘歌
故里飘歌 2020-12-10 02:41

How can I check if a double x is evenly divisible by another double y in C? With integers I would just use modulo, but what would be the correct/best way to do it with doubl

相关标签:
7条回答
  • 2020-12-10 03:24

    The concept of "even number" is only defined for integers. You can't apply it to doubles; it does not make mathematical sense. From Wikipedia:

    An even number is an integer that is "evenly divisible" by 2, i.e., divisible by 2 without remainder.

    I suggest you convert your doubles to ints, by applying whatever method you decide (rounding, truncation) and then use modulo as you suggest.

    0 讨论(0)
提交回复
热议问题