MCPcopy Create free account
hub / github.com/LancePutnam/Gamma / floatToInt

Function floatToInt

src/Conversion.cpp:35–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35int32_t floatToInt(float value){
36 Twiddle<float> u(value);
37 u.u += 0x800000;
38
39 if(u.u & 0x40000000){ // mag outside [0, 1)
40 int32_t shift = ((u.u)>>23) & 0x7F;
41 int32_t sign = u.u & MaskSign<float>();
42 int32_t result = (1<<shift) | ((u.u & MaskFrac<float>())>>(23-shift));
43
44 if(sign){ // negative number
45 result = ~result + 1; // 2's complement
46 }
47 return result;
48 }
49 else{
50 return 0;
51 }
52}
53
54float split(float value, int32_t& intPart){
55 Twiddle<float> u(value);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected