| 1 | #include <cgreen/boxed_double.h> |
| 2 | #include <stdint.h> |
| 3 | #include <stdlib.h> |
| 4 | |
| 5 | /* NOTE: while returning BoxedDouble* here seems logical, it forces casts all over the place */ |
| 6 | intptr_t box_double(double value) { |
| 7 | BoxedDouble *box = (BoxedDouble *) malloc(sizeof(BoxedDouble)); |
| 8 | box->value = value; |
| 9 | return (intptr_t)box; |
| 10 | } |
| 11 | |
| 12 | double unbox_double(intptr_t box) { |
| 13 | double value = as_double(box); |
| 14 | free((BoxedDouble *)box); |
| 15 | return value; |
| 16 | } |
| 17 | |
| 18 | double as_double(intptr_t box) { |
| 19 | return ((BoxedDouble *)box)->value; |
| 20 | } |