Is there any way to improve the performance of calculating the reciprocal of a number without losing precision? Currently I'm simply doing:
1 / (1 + a * b)
Where a
and b
are double
. Value of a
is constant. I need to do millions of such calculations.
Let's separate when a == 0
, a != 0
,
a == 0
, then answer is 1
(crystal clear) a ==!0
, let c = 1/a
(c
is also constant) then entire expression becomes
c / (b + c)
This will save one of multiplication calculation.