remove read/write_float, use to/from_f32 instead
This commit is contained in:
parent
85b7a99429
commit
95b29a249b
2 changed files with 18 additions and 25 deletions
35
capn.h
35
capn.h
|
|
@ -335,32 +335,25 @@ CAPN_INLINE int capn_write64(capn_ptr p, int off, uint64_t val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CAPN_INLINE float capn_read_float(capn_ptr p, int off, float def) {
|
CAPN_INLINE float capn_to_f32(uint32_t v) {
|
||||||
union { float f; uint32_t u;} u;
|
union { float f; uint32_t u;} u;
|
||||||
u.f = def;
|
u.u = v;
|
||||||
u.u ^= capn_read32(p, off);
|
|
||||||
return u.f;
|
return u.f;
|
||||||
}
|
}
|
||||||
CAPN_INLINE int capn_write_float(capn_ptr p, int off, float f, float def) {
|
CAPN_INLINE double capn_to_f64(uint64_t v) {
|
||||||
union { float f; uint32_t u;} u;
|
union { float f; uint64_t u;} u;
|
||||||
union { float f; uint32_t u;} d;
|
u.u = v;
|
||||||
u.f = f;
|
|
||||||
d.f = def;
|
|
||||||
return capn_write32(p, off, u.u ^ d.u);
|
|
||||||
}
|
|
||||||
|
|
||||||
CAPN_INLINE double capn_read_double(capn_ptr p, int off, double def) {
|
|
||||||
union { double f; uint64_t u;} u;
|
|
||||||
u.f = def;
|
|
||||||
u.u ^= capn_read64(p, off);
|
|
||||||
return u.f;
|
return u.f;
|
||||||
}
|
}
|
||||||
CAPN_INLINE int capn_write_double(capn_ptr p, int off, double f, double def) {
|
CAPN_INLINE uint32_t capn_from_f32(float v) {
|
||||||
union { double f; uint64_t u;} u;
|
union { float f; uint32_t u;} u;
|
||||||
union { double f; uint64_t u;} d;
|
u.f = v;
|
||||||
d.f = f;
|
return u.u;
|
||||||
u.f = f;
|
}
|
||||||
return capn_write64(p, off, u.u ^ d.u);
|
CAPN_INLINE uint64_t capn_from_f64(double v) {
|
||||||
|
union { float f; uint64_t u;} u;
|
||||||
|
u.f = v;
|
||||||
|
return u.u;
|
||||||
}
|
}
|
||||||
|
|
||||||
CAPN_INLINE capn_list8 capn_new_list8(struct capn_segment *seg, int sz) {
|
CAPN_INLINE capn_list8 capn_new_list8(struct capn_segment *seg, int sz) {
|
||||||
|
|
|
||||||
|
|
@ -195,12 +195,12 @@ void read_Value(struct Value *s, Value_ptr p) {
|
||||||
case Value_int32Value:
|
case Value_int32Value:
|
||||||
case Value_uint32Value:
|
case Value_uint32Value:
|
||||||
case Value_float32Value:
|
case Value_float32Value:
|
||||||
s->body.float32Value = capn_read_float(p.p, 8, 0.0f);
|
s->body.float32Value = capn_to_f32(capn_read32(p.p, 8));
|
||||||
break;
|
break;
|
||||||
case Value_int64Value:
|
case Value_int64Value:
|
||||||
case Value_uint64Value:
|
case Value_uint64Value:
|
||||||
case Value_float64Value:
|
case Value_float64Value:
|
||||||
s->body.float64Value = capn_read_double(p.p, 8, 0.0);
|
s->body.float64Value = capn_to_f64(capn_read64(p.p, 8));
|
||||||
break;
|
break;
|
||||||
case Value_textValue:
|
case Value_textValue:
|
||||||
s->body.textValue = capn_get_text(p.p, 0, g_nullstr);
|
s->body.textValue = capn_get_text(p.p, 0, g_nullstr);
|
||||||
|
|
@ -238,12 +238,12 @@ int write_Value(const struct Value *s, Value_ptr p) {
|
||||||
case Value_int32Value:
|
case Value_int32Value:
|
||||||
case Value_uint32Value:
|
case Value_uint32Value:
|
||||||
case Value_float32Value:
|
case Value_float32Value:
|
||||||
err = err || capn_write_float(p.p, 8, s->body.float32Value, 0.0f);
|
err = err || capn_write32(p.p, 8, capn_from_f32(s->body.float32Value));
|
||||||
break;
|
break;
|
||||||
case Value_int64Value:
|
case Value_int64Value:
|
||||||
case Value_uint64Value:
|
case Value_uint64Value:
|
||||||
case Value_float64Value:
|
case Value_float64Value:
|
||||||
err = err || capn_write_double(p.p, 4, s->body.float64Value, 0.0);
|
err = err || capn_write64(p.p, 4, capn_from_f64(s->body.float64Value));
|
||||||
break;
|
break;
|
||||||
case Value_textValue:
|
case Value_textValue:
|
||||||
err = err || capn_set_text(p.p, 0, s->body.textValue);
|
err = err || capn_set_text(p.p, 0, s->body.textValue);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue