Proposal:  F>R and FR> to support dynamically-scoped floating point variables
This proposal has been moved into this section. Its former address was: /standard/float
This page is dedicated to discussing this specific proposal
kc5tja  F>R and FR> to support dynamically-scoped floating point variablesProposal2019-03-03 06:20:52
In writing an implementation of map and reduce operations for some floating point vectors, I've had a need to save and restore dynamic variables on the R-stack. Some of these variables are floating point variables.
The lack of a floating-point stack equivalent to R> and >R made this more difficult than it should have been, I think. Therefore, I'd like to propose the following two words for consideration in the FLOATING-EXT wordset:
||Pushes the top of the floating point stack onto the return stack.|
||Pops the return stack, pushing the value removed onto the floating point stack.|
On systems where the return stack cell size differs from the floating point stack cell size, multiple cells may need to be pushed onto the R-stack, padding as appropriate. Because of alignment issues,
F>R are not guaranteed to be fast, as the implementation may have to store the floating point value in smaller parcels (e.g., storing a 64-bit or 80-bit FP value as a series of 16-bit cells on a 16-bit Forth).
Here's my current implementation written in 64-bit GForth 0.7.0 on x86-64 platform:
FVARIABLE realvar : F>R ( r -- ) ( R: -- r ) R> realvar F! realvar @ >R >R ; : FR> ( R: r -- ) ( -- r ) R> R> realvar ! realvar F@ >R ;
I'd love to hear your thoughts. Thanks for entertaining my idea.