ref: e68062e70197ebe7aded32ef48bf2aefac2c26b6
parent: f26ffca1b0f673eba1f773afcd9e3df268e8da7b
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Oct 28 22:41:06 EDT 2024
operators: shorten
--- a/operators.c
+++ b/operators.c
@@ -5,45 +5,44 @@
mpint *
conv_to_mpint(void *data, numerictype_t tag)
{
- mpint *i = mpzero;
switch(tag){
- case T_INT8: i = itomp(*(int8_t*)data, nil); break;
- case T_UINT8: i = uitomp(*(uint8_t*)data, nil); break;
- case T_INT16: i = itomp(*(int16_t*)data, nil); break;
- case T_UINT16: i = uitomp(*(uint16_t*)data, nil); break;
- case T_INT32: i = itomp(*(int32_t*)data, nil); break;
- case T_UINT32: i = uitomp(*(uint32_t*)data, nil); break;
- case T_INT64: i = vtomp(*(int64_t*)data, nil); break;
- case T_UINT64: i = uvtomp(*(int64_t*)data, nil); break;
- case T_MPINT: i = mpcopy(*(mpint**)data); break;
- case T_FLOAT: i = dtomp(*(float*)data, nil); break;
- case T_DOUBLE: i = dtomp(*(double*)data, nil); break;
+ case T_INT8: return itomp(*(int8_t*)data, nil);
+ case T_UINT8: return uitomp(*(uint8_t*)data, nil);
+ case T_INT16: return itomp(*(int16_t*)data, nil);
+ case T_UINT16: return uitomp(*(uint16_t*)data, nil);
+ case T_INT32: return itomp(*(int32_t*)data, nil);
+ case T_UINT32: return uitomp(*(uint32_t*)data, nil);
+ case T_INT64: return vtomp(*(int64_t*)data, nil);
+ case T_UINT64: return uvtomp(*(int64_t*)data, nil);
+ case T_MPINT: return mpcopy(*(mpint**)data);
+ case T_FLOAT: return dtomp(*(float*)data, nil);
+ case T_DOUBLE: return dtomp(*(double*)data, nil);
}
- return i;
+ return mpzero;
}
double
conv_to_double(void *data, numerictype_t tag)
{
- double d = 0;
+ double d;
switch(tag){
- case T_INT8: d = (double)*(int8_t*)data; break;
- case T_UINT8: d = (double)*(uint8_t*)data; break;
- case T_INT16: d = (double)*(int16_t*)data; break;
- case T_UINT16: d = (double)*(uint16_t*)data; break;
- case T_INT32: d = (double)*(int32_t*)data; break;
- case T_UINT32: d = (double)*(uint32_t*)data; break;
+ case T_INT8: return *(int8_t*)data;
+ case T_UINT8: return *(uint8_t*)data;
+ case T_INT16: return *(int16_t*)data;
+ case T_UINT16: return *(uint16_t*)data;
+ case T_INT32: return *(int32_t*)data;
+ case T_UINT32: return *(uint32_t*)data;
case T_INT64:
- d = (double)*(int64_t*)data;
+ d = *(int64_t*)data;
if(d > 0 && *(int64_t*)data < 0) // can happen!
d = -d;
- break;
- case T_UINT64: d = (double)*(uint64_t*)data; break;
- case T_MPINT: d = mptod(*(mpint**)data); break;
- case T_FLOAT: d = (double)*(float*)data; break;
+ return d;
+ case T_UINT64: return *(uint64_t*)data;
+ case T_MPINT: return mptod(*(mpint**)data);
+ case T_FLOAT: return *(float*)data;
case T_DOUBLE: return *(double*)data;
}
- return d;
+ return 0;
}
void