Constant shapes for high performance addition and multiplication for doubles

I need to efficiently add or multiply some constants to a double type result in a loop to prevent underflow. For example, if we have an int, multiplying by power 2 will be fast, since the compiler will use a bit shift. Is there a form of constants for efficient doubleaddition and multiplication?

Edit: It seems that not many understand my question, apologize for my sloppiness. I will add the code. If a- int, this (multiplication by power 2) will be more efficient

int a = 1;
for(...)
    for(...)
        a *= somefunction() * 1024;

than when replacing 1024 with 1023. Not sure if it's better if we want to add to int, but that doesn't interest me. I am interested in the case when it ais double. What are the forms of constants (e.g. force 2) that we can effectively add and multiply by double? The constant is arbitrary , it just needs to be big enough to prevent underflow.

This is probably not limited to C and C ++, but I don't know a more suitable tag.

+5
source share
6 answers

(, x *= 0x1p10;, 2 10 x *= 0x1p-10;, 2 10) ( , , ).

" " . , . , , , . , , , , , ( ) . ( .)

, ( ) , . ( , 1 , . IEEE 754 , , 0x1p-1022.)

( ). . ( 0x1p57, 0x1p-57.) , . , 30 .

+4

" " . " " . IEEE. .

union int_add_to_double
{
double this_is_your_double_precision_float;
struct your_bit_representation_of_double
    {
    int range_bit:53;//you can shift this to make range effect
    //i dont know which is mantissa bit. maybe it is first of range_bit. google it.
    int exponent_bit:10;   //exponential effect
    int sign_bit:1;     //take negative or positive
    }dont_forget_struct_name;
}and_a_union_name;
+2

.

, , . ... , "somefunction()" . "double" - IEEE, 11 52 (53 , "1" ). , 53 - " " 1024 (2 ^ 10) "1.0"... "somefunction()" , , 0,5, ( , 0.5, "a" , point . x86 , " ", - , gcc

_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);

, , , , () (- ). , , - ( ). , , "somefunction()" . , "" , -

0.5 <= X <= 2.0

, 1.0 2, , , .

+2

SSE, ( FPU ) - 4 ( → int / int- > float ). , FTZ ( ) DAZ (denormals )?

+1

frexp/ldexp, IEE 754 :

http://www.cplusplus.com/reference/clibrary/cmath/frexp/

http://www.cplusplus.com/reference/clibrary/cmath/ldexp/

:

#include <cmath>
#include <iostream>

int main ()
{
  double value = 5.4321;
  int exponent;

  double significand = frexp (value , &exponent);
  double result = ldexp (significand , exponent+1);

  std::cout << value << " -> " << result  << "\n";
  return 0;
}

: http://ideone.com/r3GBy

0

1 2 , ( ). , , 100 , - 10 . . .

, , , , , . , ALU , CPU , /.

0

All Articles