Thread: [Flashforth-devel] Floating point math for FF 5.x
Brought to you by:
oh2aun
From: om1zz <om...@vo...> - 2015-05-10 17:36:10
|
Hi, long time back I created a single precidsion floating point lib which was run on dspic33/pic24. The lib adds following math words: facos fasin fatan flog10 flog fexp fsqrt ftan fcos fsin fpow f/ f* f- f+ plus words for printing fp numbers in eng and sci notations, etc. You may find it at: https://github.com/igor-m/FlashForth-FP br Igor |
From: om1zz <om...@vo...> - 2015-05-10 18:02:47
|
..and what we need is a recogniser for floats.. It is already done for Amforth, so maybe it would be doable with FF too. Currently you can convert integers to floats or define float constants via their IEEE values in hex (see the demos). Would be great to be able to enter the floats directly, however :) I. |
From: Mikael N. <mik...@fl...> - 2015-05-11 20:41:52
|
I loaded your float number conversion routines just to check out the FP binary format. I noticed that you can skip DO..LOOP in favour of FOR NEXT and it even simplifies the code since 0 FOR NEXT just skips the loop completely. So for example: : flshiftn ( d-significand n-exponent n-times -- d n ) ?dup 0> if 0 do flshift loop then ; becomes: : flshiftn ( d-significand n-exponent n-times -- d n ) for flshift next ; All the loops in the FP code simply loop a fixed amount of times, which nicely suits the FOR NEXT. Anyway, I started to port Leons >float routine to FlashForth. Have you seen any other >float routines than Leons, that could be checked out ? BR Mike On 10.05.2015 21:02, om1zz wrote: > ..and what we need is a recogniser for floats.. It is already done for Amforth, so maybe it would be doable with FF too. > Currently you can convert integers to floats or define float constants via their IEEE values in hex (see the demos). > Would be great to be able to enter the floats directly, however :) > I. > > ------------------------------------------------------------------------------ > One dashboard for servers and applications across Physical-Virtual-Cloud > Widest out-of-the-box monitoring support with 50+ applications > Performance metrics, stats and reports that give you Actionable Insights > Deep dive visibility with transaction tracing using APM Insight. > http://ad.doubleclick.net/ddm/clk/290420510;117567292;y > _______________________________________________ > Flashforth-devel mailing list > Fla...@li... > https://lists.sourceforge.net/lists/listinfo/flashforth-devel > |
From: om1zz <om...@vo...> - 2015-05-11 21:00:52
|
>Have you seen any other >float routines than Leons, that could be >checked out ? Nope, I just worked with Leon at that time on what you can see there. The >float there requires set-recognizer and get-recognizer which come from amforth.. |
From: Mikael N. <mik...@fl...> - 2015-05-11 21:07:10
|
I think I will skip the recognizer stuff and just make >digit a deferred word inside interpret. On 12.05.2015 00:00, om1zz wrote: >> Have you seen any other >float routines than Leons, that could be >> checked out ? > Nope, I just worked with Leon at that time on what you can see there. The >float there requires set-recognizer and get-recognizer which come from amforth.. > |
From: om1zz <om...@vo...> - 2015-05-11 21:16:26
|
What about a >float word done via a C-function which does strtod() or atof()? i. |
From: om1zz <om...@vo...> - 2015-05-12 07:20:28
|
I have found in 4y old post re amforth - the quick workaround when the recognisers were not working in amforth, afaik: : # bl word count >float not abort" NaN" okstate @ if postpone fliteral then ; immediate ok # 3.444e6 fs. 3.4439998E6 ok # 1.234e6 fs. 1.23399997E6 ok # 123456789e10 fs. 1.23456776E18 ok # -1.3343e-12 # 6.222E22 f* fs. -8.3020134E10 ok # 3.44W-1 NaN I. ______________________________________________________________ > Od: om1zz <om...@vo...> > Komu: Mikael Nordman <mik...@fl...>, <fla...@li...> > Datum: 11.05.2015 23:16 > Předmět: Re: [Flashforth-devel] Floating point math for FF 5.x > >What about a >float word done via a C-function which does strtod() or atof()? >i. > >------------------------------------------------------------------------------ >One dashboard for servers and applications across Physical-Virtual-Cloud >Widest out-of-the-box monitoring support with 50+ applications >Performance metrics, stats and reports that give you Actionable Insights >Deep dive visibility with transaction tracing using APM Insight. >http://ad.doubleclick.net/ddm/clk/290420510;117567292;y >_______________________________________________ >Flashforth-devel mailing list >Fla...@li... >https://lists.sourceforge.net/lists/listinfo/flashforth-devel > |
From: om1zz <om...@vo...> - 2015-05-12 07:31:30
|
better formatted: : # bl word count >float not abort" NaN" ok state @ if postpone fliteral then ; immediate ok # 3.444e6 fs. 3.4439998E6 ok # 1.234e6 fs. 1.23399997E6 ok # 123456789e10 fs. 1.23456776E18 ok # -1.3343e-12 # 6.222E22 f* fs. -8.3020134E10 ok # 3.44W-1 NaN i. |
From: Mikael N. <mik...@fl...> - 2015-05-14 21:32:43
|
A first version that can parse and print floating point is available in git. Tested on dspic33fj128gp802. The CFloat.c file s not needed. FF calls the Microchip FP lib routines directly without any C layer. It is based on Leon Maurers FP work for Amforth. And on Igor Mokos adaptations. Just send the float.txt With ff-shell.py it looks like this: cd ff sudo shell/ff-shell.py -p /dev/ttyACM0 --xonxoff -s 38400 #send pic24/forth/float.txt ok<#,ram> f# 3.14e-9 f. 0.00000000314000 ok<#,ram> f# 3.14e-9 fs. 3.14000E-9 ok<#,ram> f# 3.14e-8 fs. 3.14000E-8 ok<#,ram> Excerpt from WORDS below: facos fasin fatan flog10 flog fexp fsqrt ftan fcos fsin fpow f/ f* f- f+ f# string>float extract fs. fe. f. f.no-space round2prc precision emitnzeros fprintdigits femitdigit emitdigit tkcofsign smlrpow10 f10^n fround fmod1 ceil floor f~ fprep4div fmin fmax f<= f>= f> f< f2* f2/ f= fabs negateiftrue fnegateifneg fnegate f0< f0= f>s f>d s>f d>f faddtoexponent f>sigexp sigexp>f fshifttoexp flshiftn flshift frshiftn frshift fmksgnd fsetsign fsetexponent fsignificand fsign fexponent frawexponent dsplit dnegateifneg d10* >= f0.5 f10 f1 f0 fliteral fvariable fconstant f! f@ fnover nfover fnswap nfswap ftuck fnip frot fswap fover fdup fdrop d>s 0> -fpmath |
From: om1zz <om...@vo...> - 2015-05-15 09:50:17
|
A test for your floats parsing experiments: \ FLOATS PARSING TEST \ IgorM 2012-15 \ TEST START f# 0e0 fs. f# -0e0 fs. f# -0e-0 fs. f# -0e-0 fs. f# +0e-0 fs. f# +0e+0 fs. f# 0.0e0 fs. f# -0.0e0 fs. f# -0.0e-0 fs. f# -0.0e-0 fs. f# +0.0e-0 fs. f# +0.0e+0 fs. f# 1e0 fs. f# -1e0 fs. f# -1e-0 fs. f# -1e-0 fs. f# +1e-0 fs. f# +1e+0 fs. f# 1.0e0 fs. f# -1.0e0 fs. f# -1.0e-0 fs. f# -1.0e-0 fs. f# +1.0e-0 fs. f# +1.0e+0 fs. f# 1.0e09 fs. f# -1.0e09 fs. f# -1.0e-09 fs. f# -1.0e-09 fs. f# +1.0e-09 fs. f# +1.0e+09 fs. f# 9e0 fs. f# -9e0 fs. f# 9e-0 fs. f# -9e+0 fs. f# 9e09 fs. f# -9e09 fs. f# 9e-09 fs. f# -9e+09 fs. f# +9e+0 fs. f# -9e+0 fs. f# +9e-0 fs. f# +9e+0 fs. f# +9e+09 fs. f# -9e+09 fs. f# +9e-09 fs. f# +9e+09 fs. f# +9.e+0 fs. f# -9.e+0 fs. f# +9.e-0 fs. f# +9.e+0 fs. f# +9.9e0 fs. f# -9.9e0 fs. f# +9.9e0 fs. f# +9.9e0 fs. f# +9.9e+0 fs. f# -9.9e+0 fs. f# +9.9e-0 fs. f# +9.9e+0 fs. f# +9.9e+09 fs. f# -9.9e+09 fs. f# +9.9e-09 fs. f# +9.9e+09 fs. f# 0.000000e0 fs. f# 0.000000e-0 fs. f# -0.000000e0 fs. f# -0.000000e-0 fs. f# +0.000000e+0 fs. f# +0.000000e-0 fs. f# -0.000000e+0 fs. f# -0.000000e-0 fs. f# 9.000000e0 fs. f# 9.000000e-0 fs. f# -9.000000e0 fs. f# -9.000000e-0 fs. f# +9.000000e+0 fs. f# +9.000000e-0 fs. f# -9.000000e+0 fs. f# -9.000000e-0 fs. f# 9.000000e09 fs. f# 9.000000e-09 fs. f# -9.000000e09 fs. f# -9.000000e-09 fs. f# +9.000000e+09 fs. f# +9.000000e-09 fs. f# -9.000000e+09 fs. f# -9.000000e-09 fs. f# 9.999000e0 fs. f# -9.999000e0 fs. f# 9.999000e9 fs. f# -9.999000e9 fs. f# 9.999000e+0 fs. f# -9.999000e+0 fs. f# 9.999000e-0 fs. f# -9.999000e-0 fs. f# 9.999000e+00 fs. f# -9.999000e+00 fs. f# 9.999000e-00 fs. f# -9.999000e-00 fs. f# 9.999999e+30 fs. f# -9.999999e+30 fs. f# 9.999999e-30 fs. f# -9.999999e-30 fs. f# 999999.9e+30 fs. f# -999999.9e+30 fs. f# 999999.9e-30 fs. f# -999999.9e-30 fs. f# 999999.9e30 fs. f# -999999.9e30 fs. f# 999999.9e-30 fs. f# -999999.9e-30 fs. f# +999999.9e30 fs. f# +999999.9e-30 fs. f# 0.000000e0 fs. f# 000000.0e-0 fs. f# 000000.0e+0 fs. f# +000000.0e-0 fs. f# +000000.0e+0 fs. f# -000000.0e-0 fs. f# -000000.0e+0 fs. f# 000000.1e-0 fs. f# 000000.1e+0 fs. f# +000000.1e-0 fs. f# +000000.1e+0 fs. f# -000000.1e-0 fs. f# -000000.1e+0 fs. f# 000000.1e-01 fs. f# 000000.1e+01 fs. f# +000000.1e-01 fs. f# +000000.1e+01 fs. f# -000000.1e-01 fs. f# -000000.1e+01 fs. f# 0.000099e+31 fs. f# -0.000099e+31 fs. f# 0.000099e-31 fs. f# -0.000099e-31 fs. f# 1.000077e+24 fs. f# -1.000077e+24 fs. f# 1.000077e-24 fs. f# -1.000077e-24 fs. f# 1.234567e0 fs. f# -1.234567e0 fs. f# 1.234567e-0 fs. f# -1.234567e-0 fs. f# 1.234567e+0 fs. f# -1.234567e+0 fs. f# 1.234567e-00 fs. f# -1.234567e+00 fs. f# 1.234567e30 fs. f# -1.234567e30 fs. f# 1.234567e+30 fs. f# -1.234567e+30 fs. f# 1.234567e-30 fs. f# -1.234567e-30 fs. f# 9.999999e+30 fs. f# -9.999999e+30 fs. f# 9.999999e-30 fs. f# -9.999999e-30 fs. f# +9.999999e+30 fs. f# -9.999999e+30 fs. f# +9.999999e-30 fs. f# -9.999999e-30 fs. f# +9.999999e30 fs. f# -9999999e30 fs. \ END OF TEST |
From: om1zz <om...@vo...> - 2015-05-15 14:33:24
|
Trying to compile for pic33 the latest trunk under MPLAB (not X) and getting linker errors - undefined reference to all those mchp floating point stuff like "___addsf3" etc. So we are missing something.. |
From: Mikael N. <mik...@fl...> - 2015-05-15 15:15:22
|
You need to add the library directory to the linker path. I did that on my mplabx/xc16 setup to make it work. I dont use old MPLAB anymore. It could also be that your lib files have different symbol names than the XC16 libraries. |
From: om1zz <om...@vo...> - 2015-05-15 15:28:34
|
It compiles fine under MPLABX.. The parse test I've send you passes ok, it seems, but I've found a small bug: ok<#,ram> f# -1000000.0e10 fs. -1.00000E16 ok<#,ram> f# -10000000.0e10 fs. -1.00000E17 ok<#,ram> f# -100000000.0e10 fs. -1.00000E18 ok<#,ram> f# -1000000000.0e10 fs. ďAS FlashForth PIC24 15.05.2015 i. ______________________________________________________________ > Od: Mikael Nordman <mik...@fl...> > Komu: <fla...@li...> > Datum: 15.05.2015 17:16 > Předmět: Re: [Flashforth-devel] Floating point math for FF 5.x > >You need to add the library directory to the linker path. > >I did that on my mplabx/xc16 setup to make it work. > >I dont use old MPLAB anymore. > >It could also be that your lib files have different symbol names than >the XC16 libraries. > > >------------------------------------------------------------------------------ >One dashboard for servers and applications across Physical-Virtual-Cloud >Widest out-of-the-box monitoring support with 50+ applications >Performance metrics, stats and reports that give you Actionable Insights >Deep dive visibility with transaction tracing using APM Insight. >http://ad.doubleclick.net/ddm/clk/290420510;117567292;y >_______________________________________________ >Flashforth-devel mailing list >Fla...@li... >https://lists.sourceforge.net/lists/listinfo/flashforth-devel > |
From: om1zz <om...@vo...> - 2015-05-15 16:12:09
|
f# 180 fs. float? f# 180. fs. float? f# 180.0 fs. float? f# 180e fs. 1.80000E2 ok<#,ram> 180 is the integer in FF 180. is the long integer in FF 180.0 - this has to be recognised as float, not sure how it is handled today in the lib.. i. |
From: Mikael N. <mik...@fl...> - 2015-05-15 16:43:22
|
Floats need always the trailing 'e'. I thank that is the forth custom. BR |
From: om1zz <om...@vo...> - 2015-05-15 16:36:58
|
\ TRIGONOMETRIC FUNCTIONS TEST - 9 degree test \ Based on "9 DEGREE" calculator test \ asin(acos(atan(tan(cos(sin(9.0)))))) == 9.0 \ other results at: \ http://www.rskey.org/~mwsebastian/miscprj/results.htm \ IgorM 2015 -trig9 marker -trig9 : Pi f# 3.14159265e ; : d2r Pi f# 180e f/ ; : r2d f# 180e Pi f/ ; : TRIG9 d2r f* fsin d2r f* fcos d2r f* ftan fatan r2d f* facos r2d f* fasin r2d f* ; \ 9.0 degree must return 9.0 degree \ not with single precision, however :) f# 9.0e TRIG9 fs. f# 9.0e TRIG9 fs. 8.88809E0 ok<#,ram> |
From: om1zz <om...@vo...> - 2015-05-15 17:02:54
|
For educational purposes :) \ Library - SIN COS TAN \ for FlashForth 5.x \ IgorM 25-9-2010 and 5/2015 \ v 3.0. \ based on 4tH library by J.L. Bezemer -fsincostan marker -fsincostan \ the original Bezemer's taylor does not work here \ as it needs a separate floating point stack!! : >taylor fdup f* fover ; \ setup for Taylor series : _taylor fover f* frot fover ; : +taylor f/ f+ frot frot ; \ add Taylor iteration : -taylor f/ f- frot frot ; \ subtract Taylor iteration \ put x in RADIANS within 2pi range : >range $0fdb $4049 fdup f+ ( x pi2 ) fover fover f/ ( x pi2 x/pi2 ) floor fover f* ( x pi2 mod ) frot fswap f- ( pi2 mod ) $0fdb $4049 fover ( pi2 mod pi mod ) f< if fswap f- else fnip then ; : _fsin fdup >taylor ( x x2 x ) _taylor $0000 $40c0 -taylor ( x-3 x2 x3 ) _taylor $0000 $42f0 +taylor ( x+5 x2 x5 ) _taylor $8000 $459d -taylor ( x-7 x2 x7 ) _taylor $3000 $48b1 +taylor ( x+9 x2 x9 ) _taylor $4540 $4c18 -taylor ( x-11 x2 x11 ) _taylor $9466 $4fb9 +taylor ( x+13 x2 x13 ) _taylor $3bbc $5398 -taylor ( x-15 x2 x15 ) _taylor $bf77 $57a1 +taylor ( x+17 x2 x17 ) _taylor $15ca $5bd8 -taylor ( x-19 x2 x19 ) fdrop fdrop ; ( x-19 ) \ calculate fsin : fsinf ( RAD -- sinus ) fdup f0< >r fabs >range fdup $0fdb $4049 f> if $0fdb $4049 f- 1 >r else 0 >r then fdup $0fdb $3fc9 f> if $0fdb $4049 fswap f- then _fsin r> if fnegate then r> if fnegate then ; \ calculate fcos : fcosf ( RAD -- cosinus ) $0fdb $3fc9 f+ fsinf ; \ calculate ftan : ftanf ( RAD -- tangens ) fdup fsinf fswap fcosf fdup f0= if abort else f/ then ; f# 0.5e fsin fs. 4.79426E-1 ok<#,ram> f# 0.5e fsinf fs. 4.79426E-1 ok<#,ram> f# 0.5e fcos fs. 8.77583E-1 ok<#,ram> f# 0.5e fcosf fs. 8.77583E-1 ok<#,ram> f# 0.5e ftan fs. 5.46303E-1 ok<#,ram> f# 0.5e ftanf fs. 5.46303E-1 ok<#,ram> |
From: Mikael N. <mik...@fl...> - 2015-05-15 17:16:23
|
Fixed. On 15.05.2015 18:28, om1zz wrote: > It compiles fine under MPLABX.. > > The parse test I've send you passes ok, it seems, but I've found a small bug: > ok<#,ram> > f# -1000000000.0e10 fs. ďAS FlashForth PIC24 15.05.2015 > |
From: om1zz <om...@vo...> - 2015-05-15 19:22:22
|
Could you set the printer precision to 7 (line 480) plz? So we can see potential issues better. Also mchp uses 6dec places in the xc16 guide, thus we can compare the values. PS: here in float.txt the precision is the number of digits to be printed in total, while xc16 uses it for number of digits after decimal point. I. |
From: om1zz <om...@vo...> - 2015-05-15 18:08:38
|
How we can see the volume of free ram and flash plz? I. |
From: Mikael N. <mik...@fl...> - 2015-05-15 18:26:52
|
#send forth/free.txt .free Flash:29607 bytes Ram:14151 bytes ok<#,ram> |
From: om1zz <om...@vo...> - 2015-05-15 18:35:32
|
Thanks!, :) I. ______________________________________________________________ > Od: Mikael Nordman <mik...@fl...> > Komu: <fla...@li...> > Datum: 15.05.2015 20:26 > Předmět: Re: [Flashforth-devel] Free memory size > >#send forth/free.txt >.free >Flash:29607 bytes >Ram:14151 bytes ok<#,ram> > >------------------------------------------------------------------------------ >One dashboard for servers and applications across Physical-Virtual-Cloud >Widest out-of-the-box monitoring support with 50+ applications >Performance metrics, stats and reports that give you Actionable Insights >Deep dive visibility with transaction tracing using APM Insight. >http://ad.doubleclick.net/ddm/clk/290420510;117567292;y >_______________________________________________ >Flashforth-devel mailing list >Fla...@li... >https://lists.sourceforge.net/lists/listinfo/flashforth-devel > |
From: om1zz <om...@vo...> - 2015-05-15 21:12:01
|
Not a critical bug, rather a feature :) f# 0.0000000000000000158e fs. 1.580000E-17 ok<#,ram> f# 9.999999999e0 fs. overflow float? f# 3.141592653589793e0 fs. overflow float? More than 7 digits to enter does not improve single precision, but maybe it could be handled somehow.. Nice to have requirement :) PS: plz remove .s from f# :) i. ______________________________________________________________ > Od: Mikael Nordman <mik...@fl...> > Komu: <fla...@li...> > Datum: 15.05.2015 19:17 > Předmět: Re: [Flashforth-devel] Floating point math for FF 5.x > >Fixed. > >On 15.05.2015 18:28, om1zz wrote: >> It compiles fine under MPLABX.. >> >> The parse test I've send you passes ok, it seems, but I've found a small bug: >> ok<#,ram> >> f# -1000000000.0e10 fs. ďAS FlashForth PIC24 15.05.2015 >> > >------------------------------------------------------------------------------ >One dashboard for servers and applications across Physical-Virtual-Cloud >Widest out-of-the-box monitoring support with 50+ applications >Performance metrics, stats and reports that give you Actionable Insights >Deep dive visibility with transaction tracing using APM Insight. >http://ad.doubleclick.net/ddm/clk/290420510;117567292;y >_______________________________________________ >Flashforth-devel mailing list >Fla...@li... >https://lists.sourceforge.net/lists/listinfo/flashforth-devel > |
From: om1zz <om...@vo...> - 2015-05-15 22:14:18
|
We have problems with large numbers and alike results, it seems. This test which worked with amforth crashes fs. : \ large positive and negative $ffff $ff7f fs. ." shall be -3.402823466e+38 " cr $ffff $7f7f fs. ." shall be 3.402823466e+38 " cr Moreover all tests where the result is undefined, and usualy returned above numbers (with my amforth asm float lib), returns now 0xffff 0x7fff from xc16 float, for example: f-1.0 flog ok<#,ram> 65535 32767 fpi/2 fasin ok<#,ram> 65535 32767 fpi/2 facos ok<#,ram> 65535 32767 what crashes fs. as well. So we must rethink how to print these states. i. |