Kusto Query Language

https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/

```kusto function
//*** Float-point Dec to dec
//*** Formula = sign * (1 + fraction) * 2^(exponent-bias)
let FloatPointDEC_to_DEC = (floatPointDec:int, sign:int){
   // sign = 1: positive, -1: negtive
   let bias = 127;
   let exponent = binary_shift_right(floatPointDec, 23);  // ==>131
   let fraction = binary_shift_right((binary_shift_left(floatPointDec,9)-binary_shift_left(binary_shift_right(floatPointDec,32-9),32)),9);  // =>2322689
   //bit_feed = 1 to 23, from left to right in fraction
   //sample fraction: 2322689(dec) eque to 01000110111000100000001(bin)
   //get fraction bit value
   let getFractionBitValue=(fraction:int, bit_feed:int){
      let m_bit = 23 + 1 - bit_feed;
      let bit_value = binary_shift_right(fraction, m_bit-1) -binary_shift_left(binary_shift_right(fraction,m_bit),1);
      todecimal(bit_value * exp2(-bit_feed))
   };
   let fraction_bit_value = getFractionBitValue(fraction, 1) + getFractionBitValue(fraction, 2)
                              + getFractionBitValue(fraction, 3) + getFractionBitValue(fraction, 4)
                              + getFractionBitValue(fraction, 5) + getFractionBitValue(fraction, 6)
                              + getFractionBitValue(fraction, 7) + getFractionBitValue(fraction, 8)
                              + getFractionBitValue(fraction, 9) + getFractionBitValue(fraction, 10)
                              + getFractionBitValue(fraction, 11) + getFractionBitValue(fraction, 12)
                              + getFractionBitValue(fraction, 13) + getFractionBitValue(fraction, 14)
                              + getFractionBitValue(fraction, 15) + getFractionBitValue(fraction, 16)
                              + getFractionBitValue(fraction, 17) + getFractionBitValue(fraction, 18)
                              + getFractionBitValue(fraction, 19) + getFractionBitValue(fraction, 20)
                              + getFractionBitValue(fraction, 21) + getFractionBitValue(fraction, 22)
                              + getFractionBitValue(fraction, 23) + 1;
   sign * fraction_bit_value * exp2(exponent - bias);
};
//print(FloatPointDEC_to_DEC(1101230337,1));

Last updated

Was this helpful?