deCONZ C++ API v2.6.1
Loading...
Searching...
No Matches
nanbox.h
1/*
2 * Copyright (c) 2023 dresden elektronik ingenieurtechnik gmbh.
3 * All rights reserved.
4 *
5 * The software in this package is published under the terms of the BSD
6 * style license a copy of which has been included with this distribution in
7 * the LICENSE.txt file.
8 *
9 */
10
11#ifndef NANBOX_H
12#define NANBOX_H
13
14#include "deconz/declspec.h"
15
59typedef enum NB_BoxType
60{
67
69
72
73typedef unsigned long long nb_word;
74
75#define NB_SHIFT_TYPE 48LLU
76#define NB_SHIFT_Q 51LLU
77#define NB_S_TO_Q_MASK 0x1fffLLU
78#define NB_TYPE_MASK 7
79
80#define NB_ATOM_SHIFT_LENGTH 24ULL
81#define NB_ATOM_LENGTH_MASK 0xFFFF
82#define NB_ATOM_PTR_MASK 0xFFFFFFUL
83
85#define NB_VALUE_NAN ((NB_S_TO_Q_MASK << NB_SHIFT_Q) | ((nb_word)NB_TYPE_NAN << NB_SHIFT_TYPE))
87#define NB_VALUE_NULL ((NB_S_TO_Q_MASK << NB_SHIFT_Q) | ((nb_word)NB_TYPE_NULL << NB_SHIFT_TYPE))
89#define NB_VALUE_TRUE ((NB_S_TO_Q_MASK << NB_SHIFT_Q) | ((nb_word)NB_TYPE_BOOL << NB_SHIFT_TYPE) | 3)
91#define NB_VALUE_FALSE ((NB_S_TO_Q_MASK << NB_SHIFT_Q) | ((nb_word)NB_TYPE_BOOL << NB_SHIFT_TYPE) | 2)
92
94#define NB_VALUE_ATOM_PTR(idx, len) ((NB_S_TO_Q_MASK << NB_SHIFT_Q) | ((nb_word)NB_TYPE_ATOM_PTR << NB_SHIFT_TYPE) | ((len) << NB_ATOM_SHIFT_LENGTH) | (idx))
95
99typedef struct NB_NanBox
100{
101 union
102 {
103 nb_word u64;
104 double f64;
105 };
106} NB_NanBox;
107
108#ifdef __cplusplus
109extern "C" {
110#endif
111
113DECONZ_DLLSPEC int NB_IsBox(struct NB_NanBox);
115DECONZ_DLLSPEC NB_BoxType NB_Type(struct NB_NanBox);
116
117#ifdef __cplusplus
118}
119#endif
120
125#endif /* NANBOX_H */
DECONZ_DLLSPEC int NB_IsBox(struct NB_NanBox)
Returns 1 if the value is NaN boxed, that is the expontent bits are 1 and TTT type is known.
Definition nanbox.c:18
NB_BoxType
3-bit enumeration refering to TTT type bits.
Definition nanbox.h:60
DECONZ_DLLSPEC NB_BoxType NB_Type(struct NB_NanBox)
Returns the type of a NaN boxed value.
Definition nanbox.c:23
@ NB_TYPE_TIMESTAMP
48-bit Unix timestamp with millisecond precision
Definition nanbox.h:65
@ NB_TYPE_NULL
null
Definition nanbox.h:62
@ NB_TYPE_DOUBLE
Not a NaN boxed value but a valid double.
Definition nanbox.h:68
@ NB_TYPE_UNKNOWN
Type can't be determined.
Definition nanbox.h:70
@ NB_TYPE_BOOL
Bool type for true and false.
Definition nanbox.h:66
@ NB_TYPE_USTRING_PTR
Used internally by UString for heap allocated strings.
Definition nanbox.h:63
@ NB_TYPE_NAN
NaN (not a number)
Definition nanbox.h:61
@ NB_TYPE_ATOM_PTR
Atom index and length.
Definition nanbox.h:64
Definition nanbox.h:100
nb_word u64
unsigned value for bit operations
Definition nanbox.h:103
double f64
double value for NB_TYPE_DOUBLE
Definition nanbox.h:104