added sml_value_to_double() to convert arbitrary sized sml_value to floating point number
This commit is contained in:
parent
5f80b0f76b
commit
18969b3bd3
2 changed files with 24 additions and 0 deletions
|
@ -50,6 +50,14 @@ sml_value *sml_value_parse(sml_buffer *buf);
|
|||
void sml_value_write(sml_value *value, sml_buffer *buf);
|
||||
void sml_value_free(sml_value *value);
|
||||
|
||||
/**
|
||||
* Cast arbitrary sized sml_value to double
|
||||
*
|
||||
* @param value the sml_value which should be casted
|
||||
* @return double value representation of sml_value, 0 if an error occured
|
||||
*/
|
||||
double sml_value_to_double(sml_value *value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -106,3 +106,19 @@ void sml_value_free(sml_value *value) {
|
|||
}
|
||||
}
|
||||
|
||||
double sml_value_to_double(sml_value *value) {
|
||||
switch (value->type) {
|
||||
case 0x51: return *value->data.int8; break;
|
||||
case 0x52: return *value->data.int16; break;
|
||||
case 0x54: return *value->data.int32; break;
|
||||
case 0x58: return *value->data.int64; break;
|
||||
case 0x61: return *value->data.uint8; break;
|
||||
case 0x62: return *value->data.uint16; break;
|
||||
case 0x64: return *value->data.uint32; break;
|
||||
case 0x68: return *value->data.uint64; break;
|
||||
|
||||
default:
|
||||
printf("error: unknown type in %s\n", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue