Hi! I’m very new to Coq (and provers in general). I’m trying to figure out how binary floats in Flocq work. My end goal is performing calculations on binary32’s and binary64’s and retrieving the result. I’ve figured out how to create a binary_float (based on this thread on stackoverflow). Here’s the code I ended up with:
How do I create a specific float (eg. a binary32 that represents the decimal value 2.5)?
How do I interpret a binary float? (I.e. how do I “translate” it to a decimal value.) For instance, Eval simpl in (Bplus mode_NE (my_binary32 false 1 2) (my_binary32 false 1 2)). returns the following:
Regarding computations, I suggest to use vm_compute instead of simpl, and also to compose your computation with a call to erase, so as to get something more readable:
Thank you for the detailed response! I do have a follow-up question: Would there be any difference in using the binary32 and binary64 types along with their respective operations, instead of the generic format binary_float? And if so, how could I create a float of these types?
Note that the types binary32 and binary64 are built on top of Binary.binary_float, while you have been using the type BinarySingleNaN.binary_float till now. The critical difference between both binary_float type is that the Binary one supports NaN signs and payloads, while the BinarySingleNaN one conflates all the NaN values into one. So, it is really a matter of which of these two theories you want to use.
As for creating numbers, the method above works for both theories, although the functions from Binary might take a few more arguments than those of BinarySingleNaN to deal with NaNs.