Packages
mmath
0.2.0-alpha2
0.2.26
0.2.25
0.2.24
0.2.23
0.2.22
0.2.21
0.2.20
0.2.19
0.2.18
0.2.17
0.2.16
0.2.15
0.2.14
0.2.13
0.2.12
0.2.11
0.2.10
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.2.0-alpha9
0.2.0-alpha8
0.2.0-alpha7
0.2.0-alpha6
0.2.0-alpha5
0.2.0-alpha4
0.2.0-alpha3
0.2.0-alpha2
0.2.0-alpha10
0.2.0-alpha1
0.2.0-alpha
0.1.17-alpha
0.1.16
0.1.15
0.1.14
0.1.13
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
math library for metric sequences and binary arrays.
Current section
Files
Jump to
Current section
Files
c_src/mmath.h
#if defined(__linux__)
# define __USE_BSD
# include <stdint.h>
# include <endian.h>
# define htonll(v) htobe64(v)
# define ntohll(v) be64toh(v)
/* On modern Os X'es (>= 10.10) htonll is defined in machine/endian.h, but on older it is missing */
#elif defined(__APPLE__) && !defined(htonll)
# include <libkern/OSByteOrder.h>
# define htonll(v) OSSwapHostToBigInt64(v)
# define ntohll(v) OSSwapBigToHostInt64(v)
#elif defined(SOLARIS)
# include <sys/byteorder.h>
#endif
#define CERTAIN 100000
typedef struct {
int64_t coefficient;
uint32_t confidence;
int8_t exponent;
} decimal;
#define DDB_ZERO htonll(0x0100000000000000LL)
#define DDB_UNSET htonll(0x0000000000000000LL)
#define IS_SET(v) ((ntohll(v) & 0xFF00000000000000LL) != 0LL)
#define FROM_DDB(v) dec_deserialize(v)
#define TO_DDB(v) dec_serialize(v)
#define GET_CHUNK(chunk) \
if (!enif_get_int64(env, argv[1], &chunk)) \
return enif_make_badarg(env); \
if (chunk < 1) \
return enif_make_badarg(env)
#define GET_BIN(pos, bin, count, vs) \
if (!enif_inspect_binary(env, argv[pos], &bin)) \
return enif_make_badarg(env); \
if (bin.size % sizeof(__typeof__(*vs))) \
return enif_make_badarg(env); \
count = bin.size / sizeof(__typeof__(*vs)); \
vs = (__typeof__(vs)) bin.data
ErlNifSInt64 dec_serialize(decimal v);
decimal dec_deserialize(ErlNifSInt64 v);
decimal dec_from_int64(int64_t v);
decimal dec_from_double(double v);
decimal dec_from_binary(int len, char* str);
int64_t dec_to_int64(decimal v);
double dec_to_double(decimal v);
decimal dec_mul(decimal v, int64_t m);
decimal dec_div(decimal v, int64_t m);
decimal dec_add(decimal a, decimal b);
decimal dec_add3(decimal a, decimal b, decimal c);
decimal dec_sub(decimal a, decimal b);
decimal dec_neg(decimal a);
int dec_cmp(decimal a, decimal b);