---+ Floating Point Unit * https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Number-Conversion.html#Number-Conversion * https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Floating-Point.html#Floating-Point * https://forth-standard.org/standard/float * https://forth-standard.org/proposals/recognizer#contribution-142 * https://de.wikipedia.org/wiki/IEEE_754 * https://interrupt.memfault.com/blog/cortex-m-rtos-context-switching ARM Cortex-M RTOS Context Switching * printf("%f", myFloat) f. fe. fs. * atof() oder strtof() benutzen? * nur single-precision? (7..8 Dezimalstellen, H7 hat double precision FPU) * kein eigener Stack * >float wo? * float register mit mutex absichern? * float.fs in source integrieren? * auf float in ISR verzichten * _FPU_USED * AN4044 Application note, Foating point unit demonstration on STM32 microcontrollers * math.h e.g. float cosf (float) =>float= in Gforth engine/support.c verwendet =strtod()= (=strtof()= for single precision) <verbatim> Cell to_float(Char *c_addr, UCell u, Float *rp) { /* convertible string := <significand>[<exponent>] <significand> := [<sign>]{<digits>[.<digits0>] | .<digits> } <exponent> := <marker><digits0> <marker> := {<e-form> | <sign-form>} <e-form> := <e-char>[<sign-form>] <sign-form> := { + | - } <e-char> := { D | d | E | e } */ Char *s = c_addr; Char c; Char *send = c_addr+u; UCell ndigits = 0; UCell ndots = 0; UCell edigits = 0; char cnum[u+3]; /* append at most "e0\0" */ char *t=cnum; char *endconv; Float r; if (s >= send) /* treat empty string as 0e */ goto return0; switch ((c=*s)) { case ' ': /* "A string of blanks should be treated as a special case representing zero."*/ for (s++; s<send; ) if (*s++ != ' ') goto error; goto return0; case '-': case '+': *t++ = c; s++; goto aftersign; } aftersign: if (s >= send) goto exponent; switch (c=*s) { case '0' ... '9': *t++ = c; ndigits++; s++; goto aftersign; case '.': *t++ = c; ndots++; s++; goto aftersign; default: goto exponent; } exponent: if (ndigits < 1 || ndots > 1) goto error; *t++ = 'E'; if (s >= send) goto done; switch (c=*s) { case 'D': case 'd': case 'E': case 'e': s++; break; } if (s >= send) goto done; switch (c=*s) { case '+': case '-': *t++ = c; s++; break; } edigits0: if (s >= send) goto done; switch (c=*s) { case '0' ... '9': *t++ = c; s++; edigits++; goto edigits0; default: goto error; } done: if (edigits == 0) *t++ = '0'; *t++ = '\0'; assert(t-cnum <= u+3); r = strtod(cnum, &endconv); assert(*endconv == '\0'); *rp = r; return -1; return0: *rp = 0.0; return -1; error: *rp = 0.0; return 0; } #endif </verbatim> -- %USERSIG{PeterSchmid - 2020-10-27}% ---++ Comments %COMMENT%
This topic: MecrispCube
>
WebHome
>
FloatingPointUnit
Topic revision: r8 - 2022-10-27 - PeterSchmid
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback