Comment #1 on issue 197 by robhamerling: Missing print procedure for float variables
http://code.google.com/p/jallib/issues/detail?id=197


I've taken the example provided with the compiler (2.4q2) and modified it a little. It depends on the print library, does not support the whole range of possible values of a float and should be enhanced to make it generally usable.

-- ---------------------------------------------------------
-- Simple float to ASCII conversion
-- Notes: - integer part limited to value of an sdword
--        - fraction limited to 6 digits
--
procedure print_float_dec(volatile byte out device, float in n) is

   var byte   d, k
   var sdword sdw

   sdw = n                                         -- integer value
   print_sdword_dec(device, sdw)
   n = n - sdw                                     -- fraction
   device = "."
k = 1 -- at least 1 digit (could be 0)
   repeat
      n = n * 10                                   -- next digit of fraction
      d = byte(n)                                  -- binary value
      device = d + "0"                             -- ASCII to device
      n = n - d                                    -- remainder
k = k + 1 -- count printed digits of fraction until ((n < 0.1) | (k > 6)) -- zero value or more than 6 digits

end procedure


--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
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 post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/jallib.
For more options, visit https://groups.google.com/d/optout.

Reply via email to