fx: split fx_number into dedicated int, uint, double, and bool types
This commit is contained in:
@@ -0,0 +1,84 @@
|
|||||||
|
#include <fx/bool.h>
|
||||||
|
#include <fx/stream.h>
|
||||||
|
|
||||||
|
/*** PRIVATE DATA *************************************************************/
|
||||||
|
|
||||||
|
struct fx_bool_p {
|
||||||
|
bool b_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
static void bool_set_value(struct fx_bool_p *i, bool v)
|
||||||
|
{
|
||||||
|
i->b_value = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool bool_get_value(struct fx_bool_p *i)
|
||||||
|
{
|
||||||
|
return i->b_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||||
|
|
||||||
|
fx_bool *fx_bool_create(bool value)
|
||||||
|
{
|
||||||
|
fx_bool *i = fx_object_create(FX_TYPE_BOOL);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_bool_p *p = fx_object_get_private(i, FX_TYPE_BOOL);
|
||||||
|
p->b_value = value;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_bool_set_value(fx_bool *i, bool v)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V(FX_TYPE_BOOL, bool_set_value, i, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_bool_get_value(const fx_bool *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_BOOL, bool_get_value, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
static void bool_init(fx_object *obj, void *priv)
|
||||||
|
{
|
||||||
|
struct fx_bool_p *i = priv;
|
||||||
|
|
||||||
|
i->b_value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void bool_fini(fx_object *obj, void *priv)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void bool_to_string(const fx_object *obj, fx_stream *out)
|
||||||
|
{
|
||||||
|
struct fx_bool_p *i = fx_object_get_private(obj, FX_TYPE_BOOL);
|
||||||
|
if (i->b_value == false) {
|
||||||
|
fx_stream_write_cstr(out, "false", NULL);
|
||||||
|
} else {
|
||||||
|
fx_stream_write_cstr(out, "true", NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_bool)
|
||||||
|
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = bool_to_string;
|
||||||
|
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_DEFINITION_END(fx_bool)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_bool)
|
||||||
|
FX_TYPE_ID(0x9c8453bf, 0xfc92, 0x4b0a, 0xbcaf, 0xd0c6cdba9310);
|
||||||
|
FX_TYPE_CLASS(fx_bool_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(struct fx_bool_p);
|
||||||
|
FX_TYPE_INSTANCE_INIT(bool_init);
|
||||||
|
FX_TYPE_INSTANCE_FINI(bool_fini);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_bool)
|
||||||
+280
@@ -0,0 +1,280 @@
|
|||||||
|
#include <fx/double.h>
|
||||||
|
#include <fx/stream.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*** PRIVATE DATA *************************************************************/
|
||||||
|
|
||||||
|
enum double_type {
|
||||||
|
DOUBLE_REGULAR = 0,
|
||||||
|
DOUBLE_INF_POSITIVE,
|
||||||
|
DOUBLE_INF_NEGATIVE,
|
||||||
|
DOUBLE_NAN_POSITIVE,
|
||||||
|
DOUBLE_NAN_NEGATIVE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fx_double_p {
|
||||||
|
enum double_type i_type;
|
||||||
|
double i_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
static bool double_get_value(const struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
return i->i_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void double_set_value(struct fx_double_p *i, double v)
|
||||||
|
{
|
||||||
|
i->i_type = DOUBLE_REGULAR;
|
||||||
|
i->i_value = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void double_set_value_nan(struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
i->i_type = DOUBLE_NAN_POSITIVE;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void double_set_value_nan_negative(struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
i->i_type = DOUBLE_NAN_NEGATIVE;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void double_set_value_inf(struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
i->i_type = DOUBLE_INF_POSITIVE;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void double_set_value_inf_negative(struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
i->i_type = DOUBLE_INF_NEGATIVE;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool double_is_nan(struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == DOUBLE_NAN_POSITIVE
|
||||||
|
|| i->i_type == DOUBLE_NAN_NEGATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool double_is_nan_positive(struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == DOUBLE_NAN_POSITIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool double_is_nan_negative(struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == DOUBLE_NAN_NEGATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool double_is_inf(struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == DOUBLE_INF_POSITIVE
|
||||||
|
|| i->i_type == DOUBLE_INF_NEGATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool double_is_inf_positive(struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == DOUBLE_INF_POSITIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool double_is_inf_negative(struct fx_double_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == DOUBLE_INF_NEGATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||||
|
|
||||||
|
fx_double *fx_double_create(double value)
|
||||||
|
{
|
||||||
|
fx_double *i = fx_object_create(FX_TYPE_DOUBLE);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_double_p *p = fx_object_get_private(i, FX_TYPE_DOUBLE);
|
||||||
|
p->i_type = DOUBLE_REGULAR;
|
||||||
|
p->i_value = value;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_double *fx_double_create_nan(void)
|
||||||
|
{
|
||||||
|
fx_double *i = fx_object_create(FX_TYPE_DOUBLE);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_double_p *p = fx_object_get_private(i, FX_TYPE_DOUBLE);
|
||||||
|
p->i_type = DOUBLE_NAN_POSITIVE;
|
||||||
|
p->i_value = 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_double *fx_double_create_nan_negative(void)
|
||||||
|
{
|
||||||
|
fx_double *i = fx_object_create(FX_TYPE_DOUBLE);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_double_p *p = fx_object_get_private(i, FX_TYPE_DOUBLE);
|
||||||
|
p->i_type = DOUBLE_NAN_NEGATIVE;
|
||||||
|
p->i_value = 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_double *fx_double_create_inf(void)
|
||||||
|
{
|
||||||
|
fx_double *i = fx_object_create(FX_TYPE_DOUBLE);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_double_p *p = fx_object_get_private(i, FX_TYPE_DOUBLE);
|
||||||
|
p->i_type = DOUBLE_INF_POSITIVE;
|
||||||
|
p->i_value = 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_double *fx_double_create_inf_negative(void)
|
||||||
|
{
|
||||||
|
fx_double *i = fx_object_create(FX_TYPE_DOUBLE);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_double_p *p = fx_object_get_private(i, FX_TYPE_DOUBLE);
|
||||||
|
p->i_type = DOUBLE_INF_NEGATIVE;
|
||||||
|
p->i_value = 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
double fx_double_get_value(const fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_get_value, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_double_set_value(fx_double *i, double v)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V(FX_TYPE_DOUBLE, double_set_value, i, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_double_set_value_nan(fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_DOUBLE, double_set_value_nan, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_double_set_value_nan_negative(fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V0(
|
||||||
|
FX_TYPE_DOUBLE,
|
||||||
|
double_set_value_nan_negative,
|
||||||
|
i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_double_set_value_inf(fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_DOUBLE, double_set_value_inf, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_double_set_value_inf_negative(fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V0(
|
||||||
|
FX_TYPE_DOUBLE,
|
||||||
|
double_set_value_inf_negative,
|
||||||
|
i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_double_is_nan(const fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_nan, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_double_is_nan_positive(const fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_nan_positive, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_double_is_nan_negative(const fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_nan_negative, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_double_is_inf(const fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_inf, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_double_is_inf_positive(const fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_inf_positive, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_double_is_inf_negative(const fx_double *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_DOUBLE, double_is_inf_negative, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
static void double_init(fx_object *obj, void *priv)
|
||||||
|
{
|
||||||
|
struct fx_double_p *i = priv;
|
||||||
|
|
||||||
|
i->i_type = DOUBLE_REGULAR;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void double_fini(fx_object *obj, void *priv)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void double_to_string(const fx_object *obj, fx_stream *out)
|
||||||
|
{
|
||||||
|
struct fx_double_p *i = fx_object_get_private(obj, FX_TYPE_DOUBLE);
|
||||||
|
switch (i->i_type) {
|
||||||
|
case DOUBLE_REGULAR:
|
||||||
|
fx_stream_write_fmt(out, NULL, "%" PRIdPTR, i->i_value);
|
||||||
|
break;
|
||||||
|
case DOUBLE_INF_POSITIVE:
|
||||||
|
fx_stream_write_cstr(out, "inf", NULL);
|
||||||
|
break;
|
||||||
|
case DOUBLE_INF_NEGATIVE:
|
||||||
|
fx_stream_write_cstr(out, "-inf", NULL);
|
||||||
|
break;
|
||||||
|
case DOUBLE_NAN_POSITIVE:
|
||||||
|
fx_stream_write_cstr(out, "NaN", NULL);
|
||||||
|
break;
|
||||||
|
case DOUBLE_NAN_NEGATIVE:
|
||||||
|
fx_stream_write_cstr(out, "-NaN", NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_double)
|
||||||
|
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = double_to_string;
|
||||||
|
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_DEFINITION_END(fx_double)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_double)
|
||||||
|
FX_TYPE_ID(0x3b20f57a, 0x2ddf, 0x4682, 0x81c4, 0x4fe404a6524e);
|
||||||
|
FX_TYPE_CLASS(fx_double_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(struct fx_double_p);
|
||||||
|
FX_TYPE_INSTANCE_INIT(double_init);
|
||||||
|
FX_TYPE_INSTANCE_FINI(double_fini);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_double)
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef FX_BOOL_H_
|
||||||
|
#define FX_BOOL_H_
|
||||||
|
|
||||||
|
#include <fx/macros.h>
|
||||||
|
|
||||||
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
|
#define FX_TYPE_BOOL (fx_bool_get_type())
|
||||||
|
|
||||||
|
FX_DECLARE_TYPE(fx_bool);
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_bool)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_bool)
|
||||||
|
|
||||||
|
FX_API fx_type fx_bool_get_type(void);
|
||||||
|
|
||||||
|
FX_API fx_bool *fx_bool_create(bool value);
|
||||||
|
|
||||||
|
FX_API void fx_bool_set_value(fx_bool *i, bool v);
|
||||||
|
|
||||||
|
FX_API bool fx_bool_get_value(const fx_bool *i);
|
||||||
|
|
||||||
|
FX_DECLS_END;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#ifndef FX_DOUBLE_H_
|
||||||
|
#define FX_DOUBLE_H_
|
||||||
|
|
||||||
|
#include <fx/macros.h>
|
||||||
|
|
||||||
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
|
#define FX_TYPE_DOUBLE (fx_double_get_type())
|
||||||
|
|
||||||
|
FX_DECLARE_TYPE(fx_double);
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_double)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_double)
|
||||||
|
|
||||||
|
FX_API fx_type fx_double_get_type(void);
|
||||||
|
|
||||||
|
FX_API fx_double *fx_double_create(double value);
|
||||||
|
FX_API fx_double *fx_double_create_nan(void);
|
||||||
|
FX_API fx_double *fx_double_create_nan_negative(void);
|
||||||
|
FX_API fx_double *fx_double_create_inf(void);
|
||||||
|
FX_API fx_double *fx_double_create_inf_negative(void);
|
||||||
|
|
||||||
|
FX_API void fx_double_set_value(fx_double *i, double v);
|
||||||
|
FX_API void fx_double_set_value_nan(fx_double *i);
|
||||||
|
FX_API void fx_double_set_value_nan_negative(fx_double *i);
|
||||||
|
FX_API void fx_double_set_value_inf(fx_double *i);
|
||||||
|
FX_API void fx_double_set_value_inf_negative(fx_double *i);
|
||||||
|
|
||||||
|
FX_API bool fx_double_is_nan(const fx_double *i);
|
||||||
|
FX_API bool fx_double_is_nan_positive(const fx_double *i);
|
||||||
|
FX_API bool fx_double_is_nan_negative(const fx_double *i);
|
||||||
|
FX_API bool fx_double_is_inf(const fx_double *i);
|
||||||
|
FX_API bool fx_double_is_inf_positive(const fx_double *i);
|
||||||
|
FX_API bool fx_double_is_inf_negative(const fx_double *i);
|
||||||
|
|
||||||
|
FX_API double fx_double_get_value(const fx_double *i);
|
||||||
|
|
||||||
|
FX_DECLS_END;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#ifndef FX_INT_H_
|
||||||
|
#define FX_INT_H_
|
||||||
|
|
||||||
|
#include <fx/macros.h>
|
||||||
|
|
||||||
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
|
#define FX_TYPE_INT (fx_int_get_type())
|
||||||
|
|
||||||
|
FX_DECLARE_TYPE(fx_int);
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_int)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_int)
|
||||||
|
|
||||||
|
FX_API fx_type fx_int_get_type(void);
|
||||||
|
|
||||||
|
FX_API fx_int *fx_int_create(intptr_t value);
|
||||||
|
FX_API fx_int *fx_int_create_nan(void);
|
||||||
|
FX_API fx_int *fx_int_create_nan_negative(void);
|
||||||
|
FX_API fx_int *fx_int_create_inf(void);
|
||||||
|
FX_API fx_int *fx_int_create_inf_negative(void);
|
||||||
|
|
||||||
|
FX_API void fx_int_set_value(fx_int *i, intptr_t v);
|
||||||
|
FX_API void fx_int_set_value_nan(fx_int *i);
|
||||||
|
FX_API void fx_int_set_value_nan_negative(fx_int *i);
|
||||||
|
FX_API void fx_int_set_value_inf(fx_int *i);
|
||||||
|
FX_API void fx_int_set_value_inf_negative(fx_int *i);
|
||||||
|
|
||||||
|
FX_API bool fx_int_is_nan(const fx_int *i);
|
||||||
|
FX_API bool fx_int_is_nan_positive(const fx_int *i);
|
||||||
|
FX_API bool fx_int_is_nan_negative(const fx_int *i);
|
||||||
|
FX_API bool fx_int_is_inf(const fx_int *i);
|
||||||
|
FX_API bool fx_int_is_inf_positive(const fx_int *i);
|
||||||
|
FX_API bool fx_int_is_inf_negative(const fx_int *i);
|
||||||
|
|
||||||
|
FX_API intptr_t fx_int_get_value(const fx_int *i);
|
||||||
|
|
||||||
|
FX_DECLS_END;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,256 +0,0 @@
|
|||||||
#ifndef FX_DS_NUMBER_H
|
|
||||||
#define FX_DS_NUMBER_H
|
|
||||||
|
|
||||||
#include <fx/macros.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
FX_DECLS_BEGIN;
|
|
||||||
|
|
||||||
#define FX_INT8(v) (fx_number_create_int8(v))
|
|
||||||
#define FX_INT16(v) (fx_number_create_int16(v))
|
|
||||||
#define FX_INT32(v) (fx_number_create_int32(v))
|
|
||||||
#define FX_INT64(v) (fx_number_create_int64(v))
|
|
||||||
#define FX_FLOAT32(v) (fx_number_create_float32(v))
|
|
||||||
#define FX_FLOAT64(v) (fx_number_create_float64(v))
|
|
||||||
#define FX_CHAR(v) (fx_number_create_char(v))
|
|
||||||
#define FX_SHORT(v) (fx_number_create_short(v))
|
|
||||||
#define FX_INT(v) (fx_number_create_int(v))
|
|
||||||
#define FX_LONG(v) (fx_number_create_long(v))
|
|
||||||
#define FX_LONGLONG(v) (fx_number_create_longlong(v))
|
|
||||||
#define FX_FLOAT(v) (fx_number_create_float(v))
|
|
||||||
#define FX_DOUBLE(v) (fx_number_create_double(v))
|
|
||||||
#define FX_SIZE_T(v) (fx_number_create_size_t(v))
|
|
||||||
|
|
||||||
#define FX_RV_INT8(v) FX_RV(fx_number_create_int8(v))
|
|
||||||
#define FX_RV_INT16(v) FX_RV(fx_number_create_int16(v))
|
|
||||||
#define FX_RV_INT32(v) FX_RV(fx_number_create_int32(v))
|
|
||||||
#define FX_RV_INT64(v) FX_RV(fx_number_create_int64(v))
|
|
||||||
#define FX_RV_FLOAT32(v) FX_RV(fx_number_create_float32(v))
|
|
||||||
#define FX_RV_FLOAT64(v) FX_RV(fx_number_create_float64(v))
|
|
||||||
#define FX_RV_CHAR(v) FX_RV(fx_number_create_char(v))
|
|
||||||
#define FX_RV_SHORT(v) FX_RV(fx_number_create_short(v))
|
|
||||||
#define FX_RV_INT(v) FX_RV(fx_number_create_int(v))
|
|
||||||
#define FX_RV_LONG(v) FX_RV(fx_number_create_long(v))
|
|
||||||
#define FX_RV_LONGLONG(v) FX_RV(fx_number_create_longlong(v))
|
|
||||||
#define FX_RV_FLOAT(v) FX_RV(fx_number_create_float(v))
|
|
||||||
#define FX_RV_DOUBLE(v) FX_RV(fx_number_create_double(v))
|
|
||||||
#define FX_RV_SIZE_T(v) FX_RV(fx_number_create_size_t(v))
|
|
||||||
|
|
||||||
#define FX_NUMBER_IVAL(p) (fx_number_get_size_t(p))
|
|
||||||
#define FX_NUMBER_FVAL(p) (fx_number_get_double(p))
|
|
||||||
|
|
||||||
#define FX_TYPE_NUMBER (fx_number_get_type())
|
|
||||||
|
|
||||||
FX_DECLARE_TYPE(fx_number);
|
|
||||||
|
|
||||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_number)
|
|
||||||
FX_TYPE_CLASS_DECLARATION_END(fx_number)
|
|
||||||
|
|
||||||
typedef enum fx_number_type {
|
|
||||||
FX_NUMBER_INT8,
|
|
||||||
FX_NUMBER_INT16,
|
|
||||||
FX_NUMBER_INT32,
|
|
||||||
FX_NUMBER_INT64,
|
|
||||||
FX_NUMBER_FLOAT32,
|
|
||||||
FX_NUMBER_FLOAT64,
|
|
||||||
FX_NUMBER_CHAR,
|
|
||||||
FX_NUMBER_SHORT,
|
|
||||||
FX_NUMBER_INT,
|
|
||||||
FX_NUMBER_LONG,
|
|
||||||
FX_NUMBER_LONGLONG,
|
|
||||||
FX_NUMBER_FLOAT,
|
|
||||||
FX_NUMBER_DOUBLE,
|
|
||||||
FX_NUMBER_SIZE_T,
|
|
||||||
FX_NUMBER_HANDLE,
|
|
||||||
FX_NUMBER_TYPE_COUNT,
|
|
||||||
|
|
||||||
FX_NUMBER_BYTE = FX_NUMBER_INT8,
|
|
||||||
FX_NUMBER_WORD = FX_NUMBER_INT16,
|
|
||||||
FX_NUMBER_DWORD = FX_NUMBER_INT32,
|
|
||||||
FX_NUMBER_QWORD = FX_NUMBER_INT64,
|
|
||||||
} fx_number_type;
|
|
||||||
|
|
||||||
FX_API fx_type fx_number_get_type(void);
|
|
||||||
|
|
||||||
FX_API fx_number *fx_number_create(fx_number_type type, void *value_ptr);
|
|
||||||
|
|
||||||
static inline fx_number *fx_number_create_int8(int8_t value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_INT8, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_int16(int16_t value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_INT16, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_int32(int32_t value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_INT32, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_int64(int64_t value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_INT64, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_float32(float value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_FLOAT32, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_float64(double value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_FLOAT64, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_char(char value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_CHAR, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_short(short value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_SHORT, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_int(int value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_INT, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_long(long value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_LONG, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_longlong(long long value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_LONGLONG, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_float(float value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_FLOAT, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_double(double value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_DOUBLE, &value);
|
|
||||||
}
|
|
||||||
static inline fx_number *fx_number_create_size_t(size_t value)
|
|
||||||
{
|
|
||||||
return fx_number_create(FX_NUMBER_SIZE_T, &value);
|
|
||||||
}
|
|
||||||
|
|
||||||
FX_API fx_number_type fx_number_get_number_type(const fx_number *number);
|
|
||||||
FX_API int fx_number_get_value(
|
|
||||||
const fx_number *number,
|
|
||||||
fx_number_type type,
|
|
||||||
void *value_ptr);
|
|
||||||
|
|
||||||
static inline int8_t fx_number_get_int8(const fx_number *number)
|
|
||||||
{
|
|
||||||
int8_t v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_INT8, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int16_t fx_number_get_int16(const fx_number *number)
|
|
||||||
{
|
|
||||||
int16_t v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_INT16, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int32_t fx_number_get_int32(const fx_number *number)
|
|
||||||
{
|
|
||||||
int32_t v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_INT32, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int64_t fx_number_get_int64(const fx_number *number)
|
|
||||||
{
|
|
||||||
int64_t v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_INT64, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline float fx_number_get_float32(const fx_number *number)
|
|
||||||
{
|
|
||||||
float v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_FLOAT32, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline double fx_number_get_float64(const fx_number *number)
|
|
||||||
{
|
|
||||||
double v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_FLOAT64, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline char fx_number_get_char(const fx_number *number)
|
|
||||||
{
|
|
||||||
char v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_CHAR, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline short fx_number_get_short(const fx_number *number)
|
|
||||||
{
|
|
||||||
short v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_SHORT, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int fx_number_get_int(const fx_number *number)
|
|
||||||
{
|
|
||||||
int v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_INT, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline long fx_number_get_long(const fx_number *number)
|
|
||||||
{
|
|
||||||
long v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_LONG, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline long long fx_number_get_longlong(const fx_number *number)
|
|
||||||
{
|
|
||||||
long long v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_LONGLONG, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline float fx_number_get_float(const fx_number *number)
|
|
||||||
{
|
|
||||||
float v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_FLOAT, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline double fx_number_get_double(const fx_number *number)
|
|
||||||
{
|
|
||||||
double v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_DOUBLE, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline size_t fx_number_get_size_t(const fx_number *number)
|
|
||||||
{
|
|
||||||
size_t v;
|
|
||||||
fx_number_get_value(number, FX_NUMBER_SIZE_T, &v);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
FX_API bool fx_number_is_integer(const fx_number *number);
|
|
||||||
FX_API bool fx_number_is_float(const fx_number *number);
|
|
||||||
FX_API bool fx_number_is_inf(const fx_number *number);
|
|
||||||
FX_API bool fx_number_is_inf_positive(const fx_number *number);
|
|
||||||
FX_API bool fx_number_is_inf_negative(const fx_number *number);
|
|
||||||
FX_API bool fx_number_is_nan(const fx_number *number);
|
|
||||||
FX_API bool fx_number_is_nan_positive(const fx_number *number);
|
|
||||||
FX_API bool fx_number_is_nan_negative(const fx_number *number);
|
|
||||||
|
|
||||||
FX_API void fx_number_set_inf_positive(fx_number *number, bool v);
|
|
||||||
FX_API void fx_number_set_inf_negative(fx_number *number, bool v);
|
|
||||||
FX_API void fx_number_set_nan_positive(fx_number *number, bool v);
|
|
||||||
FX_API void fx_number_set_nan_negative(fx_number *number, bool v);
|
|
||||||
|
|
||||||
FX_API size_t fx_number_data_size(const fx_number *number);
|
|
||||||
|
|
||||||
FX_DECLS_END;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef FX_UINT_H_
|
||||||
|
#define FX_UINT_H_
|
||||||
|
|
||||||
|
#include <fx/macros.h>
|
||||||
|
|
||||||
|
FX_DECLS_BEGIN;
|
||||||
|
|
||||||
|
#define FX_TYPE_UINT (fx_uint_get_type())
|
||||||
|
|
||||||
|
FX_DECLARE_TYPE(fx_uint);
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_uint)
|
||||||
|
FX_TYPE_CLASS_DECLARATION_END(fx_uint)
|
||||||
|
|
||||||
|
FX_API fx_type fx_uint_get_type(void);
|
||||||
|
|
||||||
|
FX_API fx_uint *fx_uint_create(uintptr_t value);
|
||||||
|
FX_API fx_uint *fx_uint_create_nan(void);
|
||||||
|
FX_API fx_uint *fx_uint_create_inf(void);
|
||||||
|
|
||||||
|
FX_API void fx_uint_set_value(fx_uint *i, uintptr_t v);
|
||||||
|
FX_API void fx_uint_set_value_nan(fx_uint *i);
|
||||||
|
FX_API void fx_uint_set_value_inf(fx_uint *i);
|
||||||
|
|
||||||
|
FX_API bool fx_uint_is_nan(const fx_uint *i);
|
||||||
|
FX_API bool fx_uint_is_inf(const fx_uint *i);
|
||||||
|
|
||||||
|
FX_API uintptr_t fx_uint_get_value(const fx_uint *i);
|
||||||
|
|
||||||
|
FX_DECLS_END;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,272 @@
|
|||||||
|
#include <fx/int.h>
|
||||||
|
#include <fx/stream.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*** PRIVATE DATA *************************************************************/
|
||||||
|
|
||||||
|
enum int_type {
|
||||||
|
INT_REGULAR = 0,
|
||||||
|
INT_INF_POSITIVE,
|
||||||
|
INT_INF_NEGATIVE,
|
||||||
|
INT_NAN_POSITIVE,
|
||||||
|
INT_NAN_NEGATIVE,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fx_int_p {
|
||||||
|
enum int_type i_type;
|
||||||
|
intptr_t i_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
static bool int_get_value(const struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
return i->i_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void int_set_value(struct fx_int_p *i, intptr_t v)
|
||||||
|
{
|
||||||
|
i->i_type = INT_REGULAR;
|
||||||
|
i->i_value = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void int_set_value_nan(struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
i->i_type = INT_NAN_POSITIVE;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void int_set_value_nan_negative(struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
i->i_type = INT_NAN_NEGATIVE;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void int_set_value_inf(struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
i->i_type = INT_INF_POSITIVE;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void int_set_value_inf_negative(struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
i->i_type = INT_INF_NEGATIVE;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool int_is_nan(struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == INT_NAN_POSITIVE || i->i_type == INT_NAN_NEGATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool int_is_nan_positive(struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == INT_NAN_POSITIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool int_is_nan_negative(struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == INT_NAN_NEGATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool int_is_inf(struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == INT_INF_POSITIVE || i->i_type == INT_INF_NEGATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool int_is_inf_positive(struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == INT_INF_POSITIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool int_is_inf_negative(struct fx_int_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == INT_INF_NEGATIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||||
|
|
||||||
|
fx_int *fx_int_create(intptr_t value)
|
||||||
|
{
|
||||||
|
fx_int *i = fx_object_create(FX_TYPE_INT);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_int_p *p = fx_object_get_private(i, FX_TYPE_INT);
|
||||||
|
p->i_type = INT_REGULAR;
|
||||||
|
p->i_value = value;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_int *fx_int_create_nan(void)
|
||||||
|
{
|
||||||
|
fx_int *i = fx_object_create(FX_TYPE_INT);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_int_p *p = fx_object_get_private(i, FX_TYPE_INT);
|
||||||
|
p->i_type = INT_NAN_POSITIVE;
|
||||||
|
p->i_value = 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_int *fx_int_create_nan_negative(void)
|
||||||
|
{
|
||||||
|
fx_int *i = fx_object_create(FX_TYPE_INT);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_int_p *p = fx_object_get_private(i, FX_TYPE_INT);
|
||||||
|
p->i_type = INT_NAN_NEGATIVE;
|
||||||
|
p->i_value = 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_int *fx_int_create_inf(void)
|
||||||
|
{
|
||||||
|
fx_int *i = fx_object_create(FX_TYPE_INT);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_int_p *p = fx_object_get_private(i, FX_TYPE_INT);
|
||||||
|
p->i_type = INT_INF_POSITIVE;
|
||||||
|
p->i_value = 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_int *fx_int_create_inf_negative(void)
|
||||||
|
{
|
||||||
|
fx_int *i = fx_object_create(FX_TYPE_INT);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_int_p *p = fx_object_get_private(i, FX_TYPE_INT);
|
||||||
|
p->i_type = INT_INF_NEGATIVE;
|
||||||
|
p->i_value = 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
intptr_t fx_int_get_value(const fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_get_value, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_int_set_value(fx_int *i, intptr_t v)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V(FX_TYPE_INT, int_set_value, i, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_int_set_value_nan(fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_INT, int_set_value_nan, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_int_set_value_nan_negative(fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_INT, int_set_value_nan_negative, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_int_set_value_inf(fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_INT, int_set_value_inf, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_int_set_value_inf_negative(fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_INT, int_set_value_inf_negative, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_int_is_nan(const fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_nan, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_int_is_nan_positive(const fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_nan_positive, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_int_is_nan_negative(const fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_nan_negative, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_int_is_inf(const fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_inf, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_int_is_inf_positive(const fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_inf_positive, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_int_is_inf_negative(const fx_int *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_INT, int_is_inf_negative, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
static void int_init(fx_object *obj, void *priv)
|
||||||
|
{
|
||||||
|
struct fx_int_p *i = priv;
|
||||||
|
|
||||||
|
i->i_type = INT_REGULAR;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void int_fini(fx_object *obj, void *priv)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void int_to_string(const fx_object *obj, fx_stream *out)
|
||||||
|
{
|
||||||
|
struct fx_int_p *i = fx_object_get_private(obj, FX_TYPE_INT);
|
||||||
|
switch (i->i_type) {
|
||||||
|
case INT_REGULAR:
|
||||||
|
fx_stream_write_fmt(out, NULL, "%" PRIdPTR, i->i_value);
|
||||||
|
break;
|
||||||
|
case INT_INF_POSITIVE:
|
||||||
|
fx_stream_write_cstr(out, "inf", NULL);
|
||||||
|
break;
|
||||||
|
case INT_INF_NEGATIVE:
|
||||||
|
fx_stream_write_cstr(out, "-inf", NULL);
|
||||||
|
break;
|
||||||
|
case INT_NAN_POSITIVE:
|
||||||
|
fx_stream_write_cstr(out, "NaN", NULL);
|
||||||
|
break;
|
||||||
|
case INT_NAN_NEGATIVE:
|
||||||
|
fx_stream_write_cstr(out, "-NaN", NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_int)
|
||||||
|
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = int_to_string;
|
||||||
|
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_DEFINITION_END(fx_int)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_int)
|
||||||
|
FX_TYPE_ID(0x3b20f57a, 0x2ddf, 0x4682, 0x81c4, 0x4fe404a6524e);
|
||||||
|
FX_TYPE_CLASS(fx_int_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(struct fx_int_p);
|
||||||
|
FX_TYPE_INSTANCE_INIT(int_init);
|
||||||
|
FX_TYPE_INSTANCE_FINI(int_fini);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_int)
|
||||||
-2499
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,174 @@
|
|||||||
|
#include <fx/stream.h>
|
||||||
|
#include <fx/uint.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*** PRIVATE DATA *************************************************************/
|
||||||
|
|
||||||
|
enum uint_type {
|
||||||
|
UINT_REGULAR = 0,
|
||||||
|
UINT_INF,
|
||||||
|
UINT_NAN,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct fx_uint_p {
|
||||||
|
enum uint_type i_type;
|
||||||
|
uintptr_t i_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
static uintptr_t uint_get_value(const struct fx_uint_p *i)
|
||||||
|
{
|
||||||
|
return i->i_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uint_set_value(struct fx_uint_p *i, uintptr_t v)
|
||||||
|
{
|
||||||
|
i->i_type = UINT_REGULAR;
|
||||||
|
i->i_value = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uint_set_value_nan(struct fx_uint_p *i)
|
||||||
|
{
|
||||||
|
i->i_type = UINT_NAN;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uint_set_value_inf(struct fx_uint_p *i)
|
||||||
|
{
|
||||||
|
i->i_type = UINT_INF;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool uint_is_nan(struct fx_uint_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == UINT_NAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool uint_is_inf(struct fx_uint_p *i)
|
||||||
|
{
|
||||||
|
return i->i_type == UINT_INF;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||||
|
|
||||||
|
fx_uint *fx_uint_create(uintptr_t value)
|
||||||
|
{
|
||||||
|
fx_uint *i = fx_object_create(FX_TYPE_UINT);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_uint_p *p = fx_object_get_private(i, FX_TYPE_UINT);
|
||||||
|
p->i_type = UINT_REGULAR;
|
||||||
|
p->i_value = value;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_uint *fx_uint_create_nan(void)
|
||||||
|
{
|
||||||
|
fx_uint *i = fx_object_create(FX_TYPE_UINT);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_uint_p *p = fx_object_get_private(i, FX_TYPE_UINT);
|
||||||
|
p->i_type = UINT_NAN;
|
||||||
|
p->i_value = 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fx_uint *fx_uint_create_inf(void)
|
||||||
|
{
|
||||||
|
fx_uint *i = fx_object_create(FX_TYPE_UINT);
|
||||||
|
if (!i) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct fx_uint_p *p = fx_object_get_private(i, FX_TYPE_UINT);
|
||||||
|
p->i_type = UINT_INF;
|
||||||
|
p->i_value = 0;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
uintptr_t fx_uint_get_value(const fx_uint *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_UINT, uint_get_value, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_uint_set_value(fx_uint *i, uintptr_t v)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V(FX_TYPE_UINT, uint_set_value, i, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_uint_set_value_nan(fx_uint *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_UINT, uint_set_value_nan, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fx_uint_set_value_inf(fx_uint *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_V0(FX_TYPE_UINT, uint_set_value_inf, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_uint_is_nan(const fx_uint *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_UINT, uint_is_nan, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_uint_is_inf(const fx_uint *i)
|
||||||
|
{
|
||||||
|
FX_CLASS_DISPATCH_STATIC_0(FX_TYPE_UINT, uint_is_inf, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||||
|
|
||||||
|
static void uint_init(fx_object *obj, void *priv)
|
||||||
|
{
|
||||||
|
struct fx_uint_p *i = priv;
|
||||||
|
|
||||||
|
i->i_type = UINT_REGULAR;
|
||||||
|
i->i_value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uint_fini(fx_object *obj, void *priv)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uint_to_string(const fx_object *obj, fx_stream *out)
|
||||||
|
{
|
||||||
|
struct fx_uint_p *i = fx_object_get_private(obj, FX_TYPE_UINT);
|
||||||
|
switch (i->i_type) {
|
||||||
|
case UINT_REGULAR:
|
||||||
|
fx_stream_write_fmt(out, NULL, "%" PRIdPTR, i->i_value);
|
||||||
|
break;
|
||||||
|
case UINT_INF:
|
||||||
|
fx_stream_write_cstr(out, "inf", NULL);
|
||||||
|
break;
|
||||||
|
case UINT_NAN:
|
||||||
|
fx_stream_write_cstr(out, "NaN", NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** CLASS DEFINITION *********************************************************/
|
||||||
|
|
||||||
|
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_uint)
|
||||||
|
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_INTERFACE_ENTRY(to_string) = uint_to_string;
|
||||||
|
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||||
|
FX_TYPE_CLASS_DEFINITION_END(fx_uint)
|
||||||
|
|
||||||
|
FX_TYPE_DEFINITION_BEGIN(fx_uint)
|
||||||
|
FX_TYPE_ID(0x79aee484, 0x5dd5, 0x463a, 0xb0c8, 0x60873abdf088);
|
||||||
|
FX_TYPE_CLASS(fx_uint_class);
|
||||||
|
FX_TYPE_INSTANCE_PRIVATE(struct fx_uint_p);
|
||||||
|
FX_TYPE_INSTANCE_INIT(uint_init);
|
||||||
|
FX_TYPE_INSTANCE_FINI(uint_fini);
|
||||||
|
FX_TYPE_DEFINITION_END(fx_uint)
|
||||||
Reference in New Issue
Block a user