c++ - Double to int conversion behind the scene? -
I'm curious to know what happens behind the scene, to change it int twice, int (5666.1) Say? Can it be more expensive for parents than a static_cast of a child's orbit? Since int and double representation is fundamentally different, it is going to be temporary and expensive during this process.
An instruction for converting floating-points into integer data to any CPU with the original floating point Will happen. That operation can take several cycles from many to many. Generally there are separate CPU registrations for FPs and integers, so you may have to use it before moving the integer to an integer register. This may be another operation, it is possibly costly for its processor manual See.
PowerPC does not include an instruction to transfer an integer register to an integer in an integer register. To store and load from FP, there should be a store in the integer. You can therefore say that a floating variable has been created.
In case of a hardware FP support, the number has to be decoded. IEEE FP format is:
icon | Exponent + bias | To convert Mantissa
, you have to do something
// Single-precise format value: int const mantissa_bits = 23; 52 52 int cost exponent_bits = 8 for doubles; 11/11 intimate exponent_bios = 127 for doubles; // 1023 for double std :: int32_t ieee; Std :: memcpy (& amp; ieee & amp; float_value, sizeof (std :: int32_t)); Std :: int32_t mantissa = ieee & amp; (1 & lt; mantissa_bits) -1 | 1 & lt; & Lt; Mantissa_bits; Intel Exponent = (ICE>> mantissa_bits & amp; (1 & lt; exponent_bits) -1) - (Exponent_bis + MNTIBBT); If (exponent = 32) {overflow (); } And {Mantissa & lt; & Lt; = Exponent; } If (IEEE and LT; 0) Mantissa = - Mantissa; Return mantissa;
I.e., some bit unpacking instructions and a change.
Comments
Post a Comment