I dabbled some in ieee floating
Point and it works but it needs a proper testing routine. 

- -------------------------------------------------------------------
-- IEE 754 floating point conversion: 1 sign bit, 8 exponent bits, 23 mantissa 
bits
-- max 3 digits after decimal point
-- source: https://www.h-schmidt.net/FloatConverter/IEEE754.html
-- source: https://www.youtube.com/watch?v=8afbTaA-gOQ
-- Original: Eur van Andel
-- -------------------------------------------------------------------
function ieee754_to_sdword(dword in fp, byte in digits) return sdword is
   var bit sign at            fp:31                      -- 1 bit sign
   var byte exponent  = byte((fp & 0x7F_80_00_00) >> 23) -- 8 bits exponent
   var dword mantissa =       fp & 0x00_7F_FF_FF         -- 23 bits mantissa
   var bit sig_bit at mantissa:22   -- most significant bit
   var dword value = 100_000        -- mantissa 1 before decimal point
   var dword fraction = 50_000      -- 6 digits total, including 1e5
   exponent = exponent - 127        -- exponent bias, fake sbyte
      
   for 22 loop                      -- 19 also enough
      if sig_bit then 
         value = value + fraction
      end if 
      mantissa = mantissa << 1
      fraction = fraction >> 1      -- add 1/2, 1/4, etc of 10^5
   end loop
    
   value = value << exponent  -- exponent max 14 here
   
   if digits == 0 then 
      value = value / 100_000  
   elsif digits == 1 then 
      value = value / 10_000
   elsif digits == 2 then 
      value = value / 1_000
   elsif digits == 3 then 
      value = value / 100
   end if                     -- more digits too slow
      
   if sign then 
      return - sdword(value)
   else 
      return sdword(value)
   end if
end function

Sent from my iPhone +31-653-286573

> On 24 May 2020, at 12:16, RobJ <[email protected]> wrote:
> 
> 
> Hi All,
> 
> Since I am running out of JAL projects and I want to spend a part of my free 
> time on improving the JAL experience so I am wondering if there are any 
> specific JAL library requests or other JAL requests.
> 
> Currently I am working on a library for the TM1637 but I am waiting for the 
> components to arrive to that I can test it after which I will add the library 
> to Jallib.
> 
> I was thinking of a library for the LoRa chip RFM95 and use the Adafruit 
> TinyLora Arduino Library as starting point but if there is no need for it I 
> could spend my time better on other JAL improvements.
> 
> So if you have suggestions, let me know. 
> 
> Thanks
> 
> Kind regards,
> 
> Rob
> -- 
> You received this message because you are subscribed to the Google Groups 
> "jallib" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jallib/82c6dd72-24af-4667-beae-5248e7460dd3%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jallib/D5F8C26D-847E-4982-B25D-603D2AE61FA4%40fiwihex.nl.

Reply via email to