I need to efficiently add or multiply some constants to a result of type double in a loop to prevent underflow. For example, if we have int, multiplying with a power of 2 will be fast as the compiler will use bit shift. Is there a form of constants for efficient double
addition and multiplication?
Edit: It seems that not many understand my question, apologies for my sloppiness . I will add some code.
If a
is a int, this (multiplying with a power of 2) will be more efficient
int a = 1;
for(...)
for(...)
a *= somefunction() * 1024;
than when 1024 is replaced with say 1023. not sure what is the best if we want to add to a int, but that is not of my interest. I am interested in the case where a
is a double. What are the forms of constants (e.g. power of 2) that we can efficiently add and multiply to a double? The constant is arbitrary, just need to be large enough to prevent underflow.
This is probably not restricted to C and C++ only, but I do not know of a more appropriate tag.