Hopefully someone who's tried this sort of thing will be able to give you a better answer, but, from my quick poking around, it seems that, while there is not a special library like racket/flonum for single-precision, Racket's generic number operations (like +) work on single-precision floats and and produce single-precision results for single-precision arguments.
A non-obvious bit of relavant documentation is the section on Reading Numbers ( http://docs.racket-lang.org/reference/reader.html#%28part._parse-number%29): "If single-precision IEEE floating point is supported (see Numbers), the marks f and s specify single-precision." (That seems to imply that there are circumstances when single-precision floats might not be supported, but I don't know whether any such circumstances actually exist.) Here's a little example: #lang racket (single-flonum? 0.0f0) ; #t (flonum? 0.0f0) ; #f ; a single-flonum? is not a flonum? (single-flonum? (+ 0.1f0 0.3f0)) ; #t (single-flonum? (real->single-flonum 1/3)) ; #t I also saw that Typed Racket has a type `Single-Flonum` and related types ( http://docs.racket-lang.org/ts-reference/type-ref.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fbase-types..rkt%29._.Single-.Flonum%29%29), which you could use to implement operators which are constrained to only work on single-precision floats. I'm not sure whether or not there are currently any optimizations that this would enable. >From what you describe, it sounds like you might also want to look at Rosette (http://docs.racket-lang.org/rosette-guide/index.html), which extends Racket to support solver-aided programming. There is also a video of a RacketCon keynote: https://www.youtube.com/watch?v=nOyIKCszNeI I'm not immediately sure how easy or hard it would be to work with single-precision floats in Rosette. -Philip On Mon, Apr 9, 2018 at 6:11 PM, <[email protected]> wrote: > Hey all, > > I'm very interested in using Racket for the purposes of numerical > analysis. Specifically, I am interested in using Racket as my test bed for > implementing simple numerical algorithms which operate on IEEE 754 single > precision floats and compare those results against a ground truth, ideally, > the exact result. Racket appears to have great support for double precision > floats, but I haven't found any functions that correspond to single > precision floats. > > Some questions: > > > 1. Should I be implementing my own versions of the flonum arithmetic > functions that operate on single precision floats? (See these functions: > https://docs.racket-lang.org/reference/flonums.html#%28part._.Flonum_ > .Arithmetic%29 > > <https://docs.racket-lang.org/reference/flonums.html#%28part._.Flonum_.Arithmetic%29> > ) > 2. What about other support functions that require knowledge of the > bit patterns of the floats? (See https://docs.racket-lang. > org/math/flonum.html#%28part._.Measuring_.Floating-.Point_.Error%29 > > <https://docs.racket-lang.org/math/flonum.html#%28part._.Measuring_.Floating-.Point_.Error%29> > or https://docs.racket-lang.org/math/flonum.html#%28part._. > Low-.Level_.Flonum_.Operations%29 > > <https://docs.racket-lang.org/math/flonum.html#%28part._.Low-.Level_.Flonum_.Operations%29> > ) > > > I would *love* to use Racket for this task and ideally, I need to have > access to all the functions on the pages linked above but for single > precision floats (half precision floats would also be nice!). > > Have I missed something obvious? > > -Dale Kim > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

