Add custom functions to allow hash and marshalling - #45
Conversation
…tinct architecture with different layout of mpfr_t is surely wrong.
|
Hi @craff and thanks for this PR! I'm sorry I missed it, having a look at it! |
| return sizeof(mpfr_t); | ||
| } | ||
|
|
||
| static intnat custom_hash(value v) |
There was a problem hiding this comment.
I think there is two ways of defining the hash function. Hashing the representation (your proposal) vs. the value.
custom_compare is based on value comparison (mpfr_cmp) and both compare/hash must agree I think because Hashtbl uses = for example.
So hashing +0 and -0 should get to the same value: the sign shouldn't be taken into account during hashing. Same for the precision, and so on…
I don't know if I prefer the value or the representation method but I'll go for the value one to be coherent with compare. I'm not against modifying compare though but that's an API breakage that should be documented.
| return r; | ||
| } | ||
|
|
||
| static void custom_serialize(value v, |
There was a problem hiding this comment.
Special values should be handled separately (nan/inf/zero), their limbs are uninitialized so they should not be part of the (de)serialization.
| /****************************/ | ||
| /* Initialization Functions */ | ||
| /****************************/ | ||
| CAMLprim value mlmpfr_init_custom() |
There was a problem hiding this comment.
Please rename it to caml_mpfr_init_custom for consistency. It could take an argument too I guess: value unit.
Add custom functions to allow hash and marshaling
WARNING: marshaling across architecture fails if mpfr_t internal changes. (the hash changes too). An architecture independent marshaling is hard because mpfr does not provide robust float to string - string to float function. Only an import and export to file!
This is already better than nothing I think.