Hi Seb, My routines are pretty Crude. They use 3 bytes for the mantissa and one for the exponent. The exponent is base10, so numbers from 10^-127 to 10^128 are supported. The price is less efficient use of the mantissa, losing about 2.5 bits accuracy. And with one sign bit, this leaves about 28 bits resolution. It works, but would not win a beauty contest. The good thing is it makes convertion to/from integers with a ^10 offset straight forward. If someone could create conversions from x*y^10 to a*b^2 and vice versa, much better results will be achieved.
As for your original question: i think a sample of unit conversion using fixed point math would be just as usefull as a sample + library. And wrt printing: format.jal does the job, although its parameters are not handled the same in different cases. Not a real issue once you have it working. Somewhere in the svn, there is a fixed version, but that does - by definition - create a different output for the same parameters. Iirc, the lib was never properly tested. Joep Op zondag 10 maart 2013 schreef Sebastien Lelong ([email protected]<javascript:_e({}, 'cvml', '[email protected]');>) het volgende: > Hi guys, > > How can we proceed ? In my original post, there are two points: unit > conversion, and floating point (or fixed point, I'm not sure now :)). > Choosing units is just a matter of agreement (though it could be hard) > > Joep, you say you store floats in a dword, but how do you specify the > mantissa/exponent ? Is it somewhat coded ? > > Cheers, > Seb > > > > On 10 March 2013 12:59, Joep Suijs <[email protected]> wrote: > >> IMHO we have a few different issues here: >> >> - conversion of inches to mm is just a case of proper scaling of fixed >> integers. I think a sample on how to do this is just as usefull for a >> user than an example of how to use a library. >> >> - fixed integer support routines are trivial as long as the scaling of >> the int's is the same. I can imagine that it would help users to have >> routines to handle this though. A well-designed API is mandatory. >> The most important thing required are printing routines that present >> the scaled integer in different ways. Format.jal is supposed to do >> this, but there are issues with this library and it could be extended. >> >> Note that the step from fixed point to floating point is not so big. >> Basically, you add the info on the scaling of the fixed point to the >> variable. One would however choose a ^2 scaling, while in fixed point >> ^10 scaling is common. >> >> My 2c >> Joep >> >> 2013/3/10 Sebastien Lelong <[email protected]>: >> > Hi guys, >> > >> > I'm playing with a sonar (Maxbotix EZ1). This sensor can give results in >> > inches. Which means nothing to me. So I was planning to create a >> "units.jal" >> > library, which would provide helpers for unit conversion. >> > >> > But how ?... >> > >> > function units_inches2cm(word in inchval) return dword is >> > ... >> > end function >> > >> > Several questions: >> > >> > - It takes a "word" as input, so should return a dword since 1 inch = >> 2.54 >> > cm. But it could also take a dword. or a 5*byte, etc... How should we >> deal >> > with this ? As in print.jal, with type dedicated function ? >> > (units_dword_inch2cm, units_word_inch2cm, etc...) >> > >> > - how should we deal with floating point values ? For the cm2inch >> > conversion, there could be such values involved. Can jalv2 record help ? >> > >> > record fp is >> > word mantissa >> > word exponent >> > end record >> > >> > or >> > >> > record fp is >> > word before_point >> > word after_point >> > end record >> > >> > such record would then be used by print.jal, etc... >> > >> > >> > Any hints, ideas, suggestions ? >> > >> > Let's not talk about how greedy it would be, how much memory and >> computation >> > it would need... >> > >> > Cheers >> > Seb >> > >> > -- >> > Sébastien Lelong >> > >> > -- >> > 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?hl=en. >> > For more options, visit https://groups.google.com/groups/opt_out. >> > >> > >> >> -- >> 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?hl=en. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > -- > Sébastien Lelong > > -- > 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?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- 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?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
