BT_FIELD_CLASS_TYPE_SIGNED_INTEGER = 3,
BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION = 4,
BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION = 5,
- BT_FIELD_CLASS_TYPE_REAL = 6,
- BT_FIELD_CLASS_TYPE_STRING = 7,
- BT_FIELD_CLASS_TYPE_STRUCTURE = 8,
- BT_FIELD_CLASS_TYPE_STATIC_ARRAY = 9,
- BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY = 10,
- BT_FIELD_CLASS_TYPE_OPTION = 11,
- BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR = 12,
- BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR = 13,
- BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR = 14,
+ BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL = 6,
+ BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL = 7,
+ BT_FIELD_CLASS_TYPE_STRING = 8,
+ BT_FIELD_CLASS_TYPE_STRUCTURE = 9,
+ BT_FIELD_CLASS_TYPE_STATIC_ARRAY = 10,
+ BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY = 11,
+ BT_FIELD_CLASS_TYPE_OPTION = 12,
+ BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR = 13,
+ BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR = 14,
+ BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR = 15,
} bt_field_class_type;
typedef enum bt_field_class_integer_preferred_display_base {
bt_field_class_integer_get_preferred_display_base(
const bt_field_class *field_class);
-extern bt_bool bt_field_class_real_is_single_precision(
- const bt_field_class *field_class);
-
extern uint64_t bt_field_class_enumeration_get_mapping_count(
const bt_field_class *field_class);
bt_field_class *field_class,
bt_field_class_integer_preferred_display_base base);
-extern bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class);
+extern bt_field_class *bt_field_class_real_single_precision_create(
+ bt_trace_class *trace_class);
-extern void bt_field_class_real_set_is_single_precision(
- bt_field_class *field_class,
- bt_bool is_single_precision);
+extern bt_field_class *bt_field_class_real_double_precision_create(
+ bt_trace_class *trace_class);
extern bt_field_class *bt_field_class_enumeration_unsigned_create(
bt_trace_class *trace_class);
extern uint64_t bt_field_integer_unsigned_get_value(
const bt_field *field);
-extern double bt_field_real_get_value(const bt_field *field);
+extern float bt_field_real_single_precision_get_value(const bt_field *field);
+
+extern double bt_field_real_double_precision_get_value(const bt_field *field);
typedef enum bt_field_enumeration_get_mapping_labels_status {
BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
extern void bt_field_integer_unsigned_set_value(bt_field *field,
uint64_t value);
-extern void bt_field_real_set_value(bt_field *field, double value);
+extern void bt_field_real_single_precision_set_value(bt_field *field,
+ float value);
+
+extern void bt_field_real_double_precision_set_value(bt_field *field,
+ double value);
typedef enum bt_field_string_set_value_status {
BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR = __BT_FUNC_STATUS_MEMORY_ERROR,
from bt2.field import _UnsignedIntegerField
from bt2.field import _SignedIntegerField
from bt2.field import _RealField
+from bt2.field import _SinglePrecisionRealField
+from bt2.field import _DoublePrecisionRealField
from bt2.field import _EnumerationField
from bt2.field import _UnsignedEnumerationField
from bt2.field import _SignedEnumerationField
from bt2.field import _UnsignedIntegerFieldConst
from bt2.field import _SignedIntegerFieldConst
from bt2.field import _RealFieldConst
+from bt2.field import _SinglePrecisionRealFieldConst
+from bt2.field import _DoublePrecisionRealFieldConst
from bt2.field import _EnumerationFieldConst
from bt2.field import _UnsignedEnumerationFieldConst
from bt2.field import _SignedEnumerationFieldConst
return float(value)
+
+class _SinglePrecisionRealFieldConst(_RealFieldConst):
+ _NAME = 'Const single-precision real'
+
+ @property
+ def _value(self):
+ return native_bt.field_real_single_precision_get_value(self._ptr)
+
+
+class _DoublePrecisionRealFieldConst(_RealFieldConst):
+ _NAME = 'Const double-precision real'
+
@property
def _value(self):
- return native_bt.field_real_get_value(self._ptr)
+ return native_bt.field_real_double_precision_get_value(self._ptr)
class _RealField(_RealFieldConst, _NumericField):
_NAME = 'Real'
+
+class _SinglePrecisionRealField(_SinglePrecisionRealFieldConst, _RealField):
+ _NAME = 'Single-precision real'
+
+ def _set_value(self, value):
+ value = self._value_to_float(value)
+ native_bt.field_real_single_precision_set_value(self._ptr, value)
+
+ value = property(fset=_set_value)
+
+
+class _DoublePrecisionRealField(_DoublePrecisionRealFieldConst, _RealField):
+ _NAME = 'Double-precision real'
+
def _set_value(self, value):
value = self._value_to_float(value)
- native_bt.field_real_set_value(self._ptr, value)
+ native_bt.field_real_double_precision_set_value(self._ptr, value)
value = property(fset=_set_value)
native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayFieldConst,
native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldConst,
native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerFieldConst,
- native_bt.FIELD_CLASS_TYPE_REAL: _RealFieldConst,
+ native_bt.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: _SinglePrecisionRealFieldConst,
+ native_bt.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: _DoublePrecisionRealFieldConst,
native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationFieldConst,
native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationFieldConst,
native_bt.FIELD_CLASS_TYPE_STRING: _StringFieldConst,
native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayField,
native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerField,
native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerField,
- native_bt.FIELD_CLASS_TYPE_REAL: _RealField,
+ native_bt.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: _SinglePrecisionRealField,
+ native_bt.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: _DoublePrecisionRealField,
native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationField,
native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationField,
native_bt.FIELD_CLASS_TYPE_STRING: _StringField,
class _RealFieldClassConst(_FieldClassConst):
- _NAME = 'Const real'
+ pass
- @property
- def is_single_precision(self):
- return native_bt.field_class_real_is_single_precision(self._ptr)
+
+class _SinglePrecisionRealFieldClassConst(_RealFieldClassConst):
+ _NAME = 'Const single-precision real'
+
+
+class _DoublePrecisionRealFieldClassConst(_RealFieldClassConst):
+ _NAME = 'Const double-precision real'
class _RealFieldClass(_FieldClass, _RealFieldClassConst):
- _NAME = 'Real'
+ pass
+
+
+class _SinglePrecisionRealFieldClass(_RealFieldClass):
+ _NAME = 'Single-precision real'
- def _is_single_precision(self, is_single_precision):
- utils._check_bool(is_single_precision)
- native_bt.field_class_real_set_is_single_precision(
- self._ptr, is_single_precision
- )
- _is_single_precision = property(fset=_is_single_precision)
+class _DoublePrecisionRealFieldClass(_RealFieldClass):
+ _NAME = 'Double-precision real'
# an enumeration field class mapping does not have a reference count, so
native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayFieldClassConst,
native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldClassConst,
native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerFieldClassConst,
- native_bt.FIELD_CLASS_TYPE_REAL: _RealFieldClassConst,
+ native_bt.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: _SinglePrecisionRealFieldClassConst,
+ native_bt.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: _DoublePrecisionRealFieldClassConst,
native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationFieldClassConst,
native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationFieldClassConst,
native_bt.FIELD_CLASS_TYPE_STRING: _StringFieldClassConst,
native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayFieldClass,
native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldClass,
native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerFieldClass,
- native_bt.FIELD_CLASS_TYPE_REAL: _RealFieldClass,
+ native_bt.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: _SinglePrecisionRealFieldClass,
+ native_bt.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: _DoublePrecisionRealFieldClass,
native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationFieldClass,
native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationFieldClass,
native_bt.FIELD_CLASS_TYPE_STRING: _StringFieldClass,
user_attributes,
)
- def create_real_field_class(self, is_single_precision=False, user_attributes=None):
- field_class_ptr = native_bt.field_class_real_create(self._ptr)
- self._check_field_class_create_status(field_class_ptr, 'real')
+ def create_single_precision_real_field_class(self, user_attributes=None):
+ field_class_ptr = native_bt.field_class_real_single_precision_create(self._ptr)
+ self._check_field_class_create_status(field_class_ptr, 'single-precision real')
- field_class = bt2_field_class._RealFieldClass._create_from_ptr(field_class_ptr)
+ field_class = bt2_field_class._SinglePrecisionRealFieldClass._create_from_ptr(
+ field_class_ptr
+ )
+
+ self._set_field_class_user_attrs(field_class, user_attributes)
+
+ return field_class
+
+ def create_double_precision_real_field_class(self, user_attributes=None):
+ field_class_ptr = native_bt.field_class_real_double_precision_create(self._ptr)
+ self._check_field_class_create_status(field_class_ptr, 'double-precision real')
+
+ field_class = bt2_field_class._DoublePrecisionRealFieldClass._create_from_ptr(
+ field_class_ptr
+ )
- field_class._is_single_precision = is_single_precision
self._set_field_class_user_attrs(field_class, user_attributes)
return field_class
return "UNSIGNED_INTEGER";
case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
return "SIGNED_INTEGER";
- case BT_FIELD_CLASS_TYPE_REAL:
- return "REAL";
+ case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+ return "SINGLE_PRECISION_REAL";
+ case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+ return "DOUBLE_PRECISION_REAL";
case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
return "UNSIGNED_ENUMERATION";
case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
format_integer_field_class(buf_ch, extended, prefix, field_class);
break;
}
- case BT_FIELD_CLASS_TYPE_REAL:
- {
- const struct bt_field_class_real *real_fc = (void *) field_class;
-
- BUF_APPEND(", %sis-single-precision=%d",
- PRFIELD(real_fc->is_single_precision));
- break;
- }
case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
{
format_field_integer_extended(buf_ch, prefix, field);
break;
}
- case BT_FIELD_CLASS_TYPE_REAL:
+ case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+ case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
{
const struct bt_field_real *real_field = (const void *) field;
g_free(obj);
}
-struct bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class)
+static
+struct bt_field_class *create_real_field_class(bt_trace_class *trace_class,
+ enum bt_field_class_type type)
{
struct bt_field_class_real *real_fc = NULL;
BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
- BT_LOGD_STR("Creating default real field class object.");
+ BT_LOGD("Creating default real field class object: type=%s",
+ bt_common_field_class_type_string(type));
real_fc = g_new0(struct bt_field_class_real, 1);
if (!real_fc) {
BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class.");
goto error;
}
- if (init_field_class((void *) real_fc, BT_FIELD_CLASS_TYPE_REAL,
- destroy_real_field_class)) {
+ if (init_field_class((void *) real_fc, type, destroy_real_field_class)) {
goto error;
}
return (void *) real_fc;
}
-bt_bool bt_field_class_real_is_single_precision(const struct bt_field_class *fc)
+struct bt_field_class *bt_field_class_real_single_precision_create(
+ bt_trace_class *trace_class)
{
- const struct bt_field_class_real *real_fc = (const void *) fc;
-
- BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class");
- BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_REAL, "Field class");
- return real_fc->is_single_precision;
+ return create_real_field_class(trace_class,
+ BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL);
}
-void bt_field_class_real_set_is_single_precision(struct bt_field_class *fc,
- bt_bool is_single_precision)
+struct bt_field_class *bt_field_class_real_double_precision_create(
+ bt_trace_class *trace_class)
{
- struct bt_field_class_real *real_fc = (void *) fc;
-
- BT_ASSERT_PRE_NON_NULL(fc, "Field class");
- BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_REAL, "Field class");
- BT_ASSERT_PRE_DEV_FC_HOT(fc, "Field class");
- real_fc->is_single_precision = (bool) is_single_precision;
- BT_LIB_LOGD("Set real field class's \"is single precision\" property: "
- "%!+F", fc);
+ return create_real_field_class(trace_class,
+ BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL);
}
static
struct bt_field_class_real {
struct bt_field_class common;
- bool is_single_precision;
};
struct bt_field_class_string {
static
struct bt_field *create_structure_field(struct bt_field_class *);
-
static
struct bt_field *create_static_array_field(struct bt_field_class *);
[BT_FIELD_CLASS_TYPE_SIGNED_INTEGER] = create_integer_field,
[BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION] = create_integer_field,
[BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION] = create_integer_field,
- [BT_FIELD_CLASS_TYPE_REAL] = create_real_field,
+ [BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL] = create_real_field,
+ [BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL] = create_real_field,
[BT_FIELD_CLASS_TYPE_STRING] = create_string_field,
[BT_FIELD_CLASS_TYPE_STRUCTURE] = create_structure_field,
[BT_FIELD_CLASS_TYPE_STATIC_ARRAY] = create_static_array_field,
[BT_FIELD_CLASS_TYPE_SIGNED_INTEGER] = destroy_integer_field,
[BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION] = destroy_integer_field,
[BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION] = destroy_integer_field,
- [BT_FIELD_CLASS_TYPE_REAL] = destroy_real_field,
+ [BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL] = destroy_real_field,
+ [BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL] = destroy_real_field,
[BT_FIELD_CLASS_TYPE_STRING] = destroy_string_field,
[BT_FIELD_CLASS_TYPE_STRUCTURE] = destroy_structure_field,
[BT_FIELD_CLASS_TYPE_STATIC_ARRAY] = destroy_array_field,
bt_field_set_single(field, true);
}
-double bt_field_real_get_value(const struct bt_field *field)
+float bt_field_real_single_precision_get_value(const struct bt_field *field)
+{
+ const struct bt_field_real *real_field = (const void *) field;
+
+ BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+ BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+ BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+ BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, "Field");
+ return (float) real_field->value;
+}
+
+double bt_field_real_double_precision_get_value(const struct bt_field *field)
{
const struct bt_field_real *real_field = (const void *) field;
BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
- BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
+ BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+ BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, "Field");
+
return real_field->value;
}
-void bt_field_real_set_value(struct bt_field *field, double value)
+void bt_field_real_single_precision_set_value(struct bt_field *field,
+ float value)
{
struct bt_field_real *real_field = (void *) field;
BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
- BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
+ BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+ BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, "Field");
BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
- BT_ASSERT_PRE_DEV(
- !((struct bt_field_class_real *) field->class)->is_single_precision ||
- (double) (float) value == value,
- "Invalid value for a single-precision real number: value=%f, "
- "%![fc-]+F", value, field->class);
+
+ real_field->value = (double) value;
+ bt_field_set_single(field, true);
+}
+
+void bt_field_real_double_precision_set_value(struct bt_field *field,
+ double value)
+{
+ struct bt_field_real *real_field = (void *) field;
+
+ BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+ BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+ BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, "Field");
+ BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+
real_field->value = value;
bt_field_set_single(field, true);
}
{
bt_field_class *ir_fc;
- ir_fc = bt_field_class_real_create(ctx->ir_tc);
- BT_ASSERT(ir_fc);
-
if (fc->base.size == 32) {
- bt_field_class_real_set_is_single_precision(ir_fc,
- BT_TRUE);
+ ir_fc = bt_field_class_real_single_precision_create(ctx->ir_tc);
+ } else {
+ ir_fc = bt_field_class_real_double_precision_create(ctx->ir_tc);
}
+ BT_ASSERT(ir_fc);
return ir_fc;
}
}
field = borrow_next_field(notit);
+ bt_field_class_type type = bt_field_get_class_type(field);
BT_ASSERT(field);
BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
- BT_ASSERT(bt_field_get_class_type(field) ==
- BT_FIELD_CLASS_TYPE_REAL);
- bt_field_real_set_value(field, value);
+ BT_ASSERT(type == BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL ||
+ type == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL);
+
+ if (type == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) {
+ bt_field_real_single_precision_set_value(field, (float) value);
+ } else {
+ bt_field_real_double_precision_set_value(field, value);
+ }
stack_top(notit->stack)->index++;
end:
BT_ASSERT(fc);
_fs_sink_ctf_field_class_bit_array_init((void *) fc,
FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT,
- ir_fc, bt_field_class_real_is_single_precision(ir_fc) ? 32 : 64,
+ ir_fc,
+ bt_field_class_get_type(ir_fc) == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL ? 32 : 64,
index_in_parent);
return fc;
}
struct fs_sink_ctf_field_class_float *fc, const bt_field *field)
{
int ret;
- double val = bt_field_real_get_value(field);
+ double val;
if (fc->base.size == 32) {
+ val = (double) bt_field_real_single_precision_get_value(field);
ret = bt_ctfser_write_float32(&stream->ctfser, val,
fc->base.base.alignment, BYTE_ORDER);
} else {
+ val = bt_field_real_double_precision_get_value(field);
ret = bt_ctfser_write_float64(&stream->ctfser, val,
fc->base.base.alignment, BYTE_ORDER);
}
{
unsigned int mant_dig, exp_dig;
- if (bt_field_class_real_is_single_precision(fc->base.base.ir_fc)) {
+ if (bt_field_class_get_type(fc->base.base.ir_fc) == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) {
mant_dig = 24;
exp_dig = 8;
} else {
case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
ret = translate_integer_field_class(ctx);
break;
- case BT_FIELD_CLASS_TYPE_REAL:
+ case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+ case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
ret = translate_real_field_class(ctx);
break;
case BT_FIELD_CLASS_TYPE_STRING:
bt_field_integer_signed_set_value(out_field,
bt_field_integer_signed_get_value(in_field));
break;
- case BT_FIELD_CLASS_TYPE_REAL:
- bt_field_real_set_value(out_field,
- bt_field_real_get_value(in_field));
+ case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+ bt_field_real_single_precision_set_value(out_field,
+ bt_field_real_single_precision_get_value(in_field));
+ break;
+ case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+ bt_field_real_double_precision_set_value(out_field,
+ bt_field_real_double_precision_get_value(in_field));
break;
case BT_FIELD_CLASS_TYPE_STRING:
{
}
static inline
-int field_class_real_copy(
+int field_class_single_precision_real_copy(
struct trace_ir_metadata_maps *md_maps,
const bt_field_class *in_field_class,
bt_field_class *out_field_class)
{
- BT_COMP_LOGD("Copying content of real field class: "
- "in-fc-addr=%p, out-fc-addr=%p",
- in_field_class, out_field_class);
+ BT_COMP_LOGD("Copying content of single-precision real field class: "
+ "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
- bt_field_class_real_set_is_single_precision(out_field_class,
- bt_field_class_real_is_single_precision(in_field_class));
+ BT_COMP_LOGD("Copied content single-precision real field class:"
+ "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
- BT_COMP_LOGD("Copied content real field class: in-fc-addr=%p, "
- "out-fc-addr=%p", in_field_class, out_field_class);
+ return 0;
+}
+
+static inline
+int field_class_double_precision_real_copy(
+ struct trace_ir_metadata_maps *md_maps,
+ const bt_field_class *in_field_class,
+ bt_field_class *out_field_class)
+{
+ BT_COMP_LOGD("Copying content of double-precision real field class: "
+ "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
+
+ BT_COMP_LOGD("Copied content double-precision real field class:"
+ "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
return 0;
}
out_field_class = bt_field_class_enumeration_signed_create(
md_maps->output_trace_class);
break;
- case BT_FIELD_CLASS_TYPE_REAL:
- out_field_class = bt_field_class_real_create(
+ case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+ out_field_class = bt_field_class_real_single_precision_create(
+ md_maps->output_trace_class);
+ break;
+ case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+ out_field_class = bt_field_class_real_double_precision_create(
md_maps->output_trace_class);
break;
case BT_FIELD_CLASS_TYPE_STRING:
ret = field_class_signed_enumeration_copy(md_maps,
in_field_class, out_field_class);
break;
- case BT_FIELD_CLASS_TYPE_REAL:
- ret = field_class_real_copy(md_maps,
+ case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+ ret = field_class_single_precision_real_copy(md_maps,
+ in_field_class, out_field_class);
+ break;
+ case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+ ret = field_class_double_precision_real_copy(md_maps,
in_field_class, out_field_class);
break;
case BT_FIELD_CLASS_TYPE_STRING:
case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
type = "Signed enumeration";
break;
- case BT_FIELD_CLASS_TYPE_REAL:
- type = "Real";
+ case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+ type = "Single-precision real";
+ break;
+ case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+ type = "Double-precision real";
break;
case BT_FIELD_CLASS_TYPE_STRING:
type = "String";
plural(mapping_count));
break;
}
- case BT_FIELD_CLASS_TYPE_REAL:
- if (bt_field_class_real_is_single_precision(fc)) {
- g_string_append(ctx->str, " (Single precision)");
- } else {
- g_string_append(ctx->str, " (Double precision)");
- }
-
- break;
case BT_FIELD_CLASS_TYPE_STRUCTURE:
{
uint64_t member_count =
break;
}
- case BT_FIELD_CLASS_TYPE_REAL:
+ case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+ write_sp(ctx);
+ write_float_prop_value(ctx, bt_field_real_single_precision_get_value(field));
+ break;
+ case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
write_sp(ctx);
- write_float_prop_value(ctx, bt_field_real_get_value(field));
+ write_float_prop_value(ctx, bt_field_real_double_precision_get_value(field));
break;
case BT_FIELD_CLASS_TYPE_STRING:
write_sp(ctx);
case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
return print_integer(pretty, field);
- case BT_FIELD_CLASS_TYPE_REAL:
+ case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+ case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
{
double v;
- v = bt_field_real_get_value(field);
+ if (class_id == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) {
+ v = (float) bt_field_real_single_precision_get_value(field);
+ } else {
+ v = bt_field_real_double_precision_get_value(field);
+ }
+
if (pretty->use_colors) {
bt_common_g_string_append(pretty->string, COLOR_NUMBER_VALUE);
}
cc = tc.create_structure_field_class()
cc += [
('cpu_id', tc.create_signed_integer_field_class(8)),
- ('stuff', tc.create_real_field_class()),
+ ('stuff', tc.create_double_precision_real_field_class()),
]
# packet context (stream-class-defined)
pc = tc.create_structure_field_class()
pc += [
('something', tc.create_unsigned_integer_field_class(8)),
- ('something_else', tc.create_real_field_class()),
+ (
+ 'something_else',
+ tc.create_double_precision_real_field_class(),
+ ),
]
stream_class = tc.create_stream_class(
self.assertEqual(labels, ['something', 'whole range', 'zip'])
-class RealFieldTestCase(_TestNumericField, unittest.TestCase):
+class SingleRealFieldTestCase(_TestNumericField, unittest.TestCase):
+ @staticmethod
+ def _const_value_setter(field):
+ field.value = 52.0
+
+ def _create_fc(self, tc):
+ return tc.create_single_precision_real_field_class()
+
+ def setUp(self):
+ self._tc = get_default_trace_class()
+ self._field = _create_field(self._tc, self._create_fc(self._tc))
+ self._def = _create_field(self._tc, self._create_fc(self._tc))
+ self._def_const = _create_const_field(
+ self._tc,
+ self._tc.create_single_precision_real_field_class(),
+ self._const_value_setter,
+ )
+ self._def.value = 52.0
+ self._def_value = 52.0
+ self._def_new_value = -17.0
+
+ def _test_invalid_op(self, cb):
+ with self.assertRaises(TypeError):
+ cb()
+
+ def test_assign_true(self):
+ self._def.value = True
+ self.assertTrue(self._def)
+
+ def test_assign_false(self):
+ self._def.value = False
+ self.assertFalse(self._def)
+
+ def test_assign_pos_int(self):
+ raw = 477
+ self._def.value = raw
+ self.assertEqual(self._def, float(raw))
+
+ def test_assign_neg_int(self):
+ raw = -13
+ self._def.value = raw
+ self.assertEqual(self._def, float(raw))
+
+ def test_assign_int_field(self):
+ int_fc = self._tc.create_signed_integer_field_class(32)
+ int_field = _create_field(self._tc, int_fc)
+ raw = 999
+ int_field.value = raw
+ self._def.value = int_field
+ self.assertEqual(self._def, float(raw))
+
+ def test_assign_float(self):
+ raw = -19.23
+ self._def.value = raw
+ # It's expected to have some lost of precision because of the field
+ # that is in single precision.
+ self.assertEqual(round(self._def, 5), raw)
+
+ def test_assign_float_field(self):
+ field = _create_field(self._tc, self._create_fc(self._tc))
+ raw = 101.32
+ field.value = raw
+ self._def.value = field
+ # It's expected to have some lost of precision because of the field
+ # that is in single precision.
+ self.assertEqual(round(self._def, 5), raw)
+
+ def test_assign_invalid_type(self):
+ with self.assertRaises(TypeError):
+ self._def.value = 'yes'
+
+ def test_invalid_lshift(self):
+ self._test_invalid_op(lambda: self._def << 23)
+
+ def test_invalid_rshift(self):
+ self._test_invalid_op(lambda: self._def >> 23)
+
+ def test_invalid_and(self):
+ self._test_invalid_op(lambda: self._def & 23)
+
+ def test_invalid_or(self):
+ self._test_invalid_op(lambda: self._def | 23)
+
+ def test_invalid_xor(self):
+ self._test_invalid_op(lambda: self._def ^ 23)
+
+ def test_invalid_invert(self):
+ self._test_invalid_op(lambda: ~self._def)
+
+ def test_str_op(self):
+ self.assertEqual(str(round(self._def, 5)), str(self._def_value))
+
+
+_inject_numeric_testing_methods(SingleRealFieldTestCase)
+
+
+class DoubleRealFieldTestCase(_TestNumericField, unittest.TestCase):
@staticmethod
def _const_value_setter(field):
field.value = 52.7
def _create_fc(self, tc):
- return tc.create_real_field_class()
+ return tc.create_double_precision_real_field_class()
def setUp(self):
self._tc = get_default_trace_class()
self._field = _create_field(self._tc, self._create_fc(self._tc))
self._def = _create_field(self._tc, self._create_fc(self._tc))
self._def_const = _create_const_field(
- self._tc, self._tc.create_real_field_class(), self._const_value_setter
+ self._tc,
+ self._tc.create_double_precision_real_field_class(),
+ self._const_value_setter,
)
self._def.value = 52.7
self._def_value = 52.7
self.assertEqual(str(self._def), str(self._def_value))
-_inject_numeric_testing_methods(RealFieldTestCase)
+_inject_numeric_testing_methods(DoubleRealFieldTestCase)
class StringFieldTestCase(unittest.TestCase):
self._tc = get_default_trace_class()
self._fc0_fn = self._tc.create_signed_integer_field_class
self._fc1_fn = self._tc.create_string_field_class
- self._fc2_fn = self._tc.create_real_field_class
+ self._fc2_fn = self._tc.create_double_precision_real_field_class
self._fc3_fn = self._tc.create_signed_integer_field_class
self._fc4_fn = self._tc.create_structure_field_class
self._fc5_fn = self._tc.create_structure_field_class
self.assertIs(type(field2), bt2._StringField)
self.assertEqual(field2, 'salut')
- self.assertIs(type(field3), bt2._RealField)
+ self.assertIs(type(field3), bt2._DoublePrecisionRealField)
self.assertEqual(field3, 17.5)
self.assertIs(type(field4), bt2._SignedIntegerField)
self.assertIs(type(field2), bt2._StringFieldConst)
self.assertEqual(field2, 'salut')
- self.assertIs(type(field3), bt2._RealFieldConst)
+ self.assertIs(type(field3), bt2._DoublePrecisionRealFieldConst)
self.assertEqual(field3, 17.5)
self.assertIs(type(field4), bt2._SignedIntegerFieldConst)
def _create_fc(self, tc):
ft0 = tc.create_signed_integer_field_class(32)
ft1 = tc.create_string_field_class()
- ft2 = tc.create_real_field_class()
+ ft2 = tc.create_double_precision_real_field_class()
ft3 = tc.create_signed_integer_field_class(17)
fc = tc.create_variant_field_class()
fc.append_option('corner', ft0)
self._def.selected_option_index = 2
self._def.value = -17.34
self.assertEqual(self._def.selected_option, -17.34)
- self.assertEqual(type(self._def.selected_option), bt2._RealField)
+ self.assertEqual(type(self._def.selected_option), bt2._DoublePrecisionRealField)
self._def.selected_option_index = 3
self._def.value = 1921
_create_default_field_class = _create_field_class
-class RealFieldClassTestCase(_TestFieldClass, unittest.TestCase):
+class SingleRealFieldClassTestCase(_TestFieldClass, unittest.TestCase):
@staticmethod
def _const_value_setter(field):
- field.value = -18
+ field.value = -18.0
def _create_field_class(self, *args, **kwargs):
tc = get_default_trace_class()
- return tc.create_real_field_class(*args, **kwargs)
+ return tc.create_single_precision_real_field_class(*args, **kwargs)
def _create_default_const_field_class(self, *args, **kwargs):
tc = get_default_trace_class()
- fc = tc.create_real_field_class(*args, **kwargs)
+ fc = tc.create_single_precision_real_field_class(*args, **kwargs)
return _create_const_field_class(tc, fc, self._const_value_setter)
_create_default_field_class = _create_field_class
def test_create_default(self):
fc = self._create_field_class()
- self.assertFalse(fc.is_single_precision)
self.assertEqual(len(fc.user_attributes), 0)
- def test_create_is_single_precision(self):
- fc = self._create_field_class(is_single_precision=True)
- self.assertTrue(fc.is_single_precision)
- def test_create_invalid_is_single_precision(self):
- with self.assertRaises(TypeError):
- self._create_field_class(is_single_precision='hohoho')
+class DoubleRealFieldClassTestCase(_TestFieldClass, unittest.TestCase):
+ @staticmethod
+ def _const_value_setter(field):
+ field.value = -18.0
+
+ def _create_field_class(self, *args, **kwargs):
+ tc = get_default_trace_class()
+ return tc.create_double_precision_real_field_class(*args, **kwargs)
+
+ def _create_default_const_field_class(self, *args, **kwargs):
+ tc = get_default_trace_class()
+ fc = tc.create_double_precision_real_field_class(*args, **kwargs)
+ return _create_const_field_class(tc, fc, self._const_value_setter)
+
+ _create_default_field_class = _create_field_class
+
+ def test_create_default(self):
+ fc = self._create_field_class()
+ self.assertEqual(len(fc.user_attributes), 0)
# Converts an _EnumerationFieldClassMapping to a list of ranges:
self.assertIs(type(field_class), bt2_field_class._SignedIntegerFieldClassConst)
def test_iadd(self):
- a_field_class = self._tc.create_real_field_class()
+ a_field_class = self._tc.create_single_precision_real_field_class()
b_field_class = self._tc.create_signed_integer_field_class(17)
self._append_element_method(self._fc, 'a_float', a_field_class)
self._append_element_method(self._fc, 'b_int', b_field_class)
self.assertEqual(self._fc['e_struct'].name, 'e_struct')
def test_const_iadd(self):
- a_field_class = self._tc.create_real_field_class()
+ a_field_class = self._tc.create_single_precision_real_field_class()
with self.assertRaises(TypeError):
self._fc_const += a_field_class
def test_getitem(self):
a_fc = self._tc.create_signed_integer_field_class(32)
b_fc = self._tc.create_string_field_class()
- c_fc = self._tc.create_real_field_class()
+ c_fc = self._tc.create_single_precision_real_field_class()
self._append_element_method(self._fc, 'a', a_fc)
self._append_element_method(self._fc, 'b', b_fc)
self._append_element_method(self._fc, 'c', c_fc)
def test_iter(self):
a_fc = self._tc.create_signed_integer_field_class(32)
b_fc = self._tc.create_string_field_class()
- c_fc = self._tc.create_real_field_class()
+ c_fc = self._tc.create_single_precision_real_field_class()
elements = (('a', a_fc), ('b', b_fc), ('c', c_fc))
for elem in elements:
def test_at_index(self):
a_fc = self._tc.create_signed_integer_field_class(32)
b_fc = self._tc.create_string_field_class()
- c_fc = self._tc.create_real_field_class()
+ c_fc = self._tc.create_single_precision_real_field_class()
self._append_element_method(self._fc, 'c', c_fc)
self._append_element_method(self._fc, 'a', a_fc)
self._append_element_method(self._fc, 'b', b_fc)
tc = get_default_trace_class()
fc = tc.create_structure_field_class()
- member_fc = self._tc.create_real_field_class()
+ member_fc = self._tc.create_single_precision_real_field_class()
fc.append_member('real', member_fc)
const_fc = _create_const_field_class(tc, fc, _real_value_setter)
self.assertIs(
- type(const_fc['real'].field_class), bt2_field_class._RealFieldClassConst
+ type(const_fc['real'].field_class),
+ bt2_field_class._SinglePrecisionRealFieldClassConst,
)
def test_member_field_class(self):
tc = get_default_trace_class()
fc = tc.create_structure_field_class()
- member_fc = self._tc.create_real_field_class()
+ member_fc = self._tc.create_single_precision_real_field_class()
fc.append_member('real', member_fc)
- self.assertIs(type(fc['real'].field_class), bt2_field_class._RealFieldClass)
+ self.assertIs(
+ type(fc['real'].field_class), bt2_field_class._SinglePrecisionRealFieldClass
+ )
class OptionFieldClassTestCase(_TestFieldClass, unittest.TestCase):
def _create_field_class_for_field_path_test(self):
fc = self._create_default_field_class(selector_fc=self._tag_fc)
- foo_fc = self._tc.create_real_field_class()
+ foo_fc = self._tc.create_single_precision_real_field_class()
bar_fc = self._tc.create_string_field_class()
baz_fc = self._tc.create_string_field_class()
)
def test_iadd(self):
- a_field_class = self._tc.create_real_field_class()
+ a_field_class = self._tc.create_single_precision_real_field_class()
self._fc.append_option('a_float', a_field_class, self._ranges1)
c_field_class = self._tc.create_string_field_class()
d_field_class = self._tc.create_signed_enumeration_field_class(
def test_const_iadd(self):
fc_const = self._create_default_const_field_class()
- a_field_class = self._tc.create_real_field_class()
+ a_field_class = self._tc.create_single_precision_real_field_class()
with self.assertRaises(TypeError):
fc_const += [('a_float', a_field_class, self._ranges1)]
def test_getitem(self):
a_fc = self._tc.create_signed_integer_field_class(32)
b_fc = self._tc.create_string_field_class()
- c_fc = self._tc.create_real_field_class()
+ c_fc = self._tc.create_single_precision_real_field_class()
self._fc.append_option('a', a_fc, self._ranges1)
self._fc.append_option('b', b_fc, self._ranges2)
self._fc.append_option('c', c_fc, self._ranges3)
def test_iter(self):
a_fc = self._tc.create_signed_integer_field_class(32)
b_fc = self._tc.create_string_field_class()
- c_fc = self._tc.create_real_field_class()
+ c_fc = self._tc.create_single_precision_real_field_class()
opts = (
('a', a_fc, self._ranges1),
('b', b_fc, self._ranges2),
def test_at_index(self):
a_fc = self._tc.create_signed_integer_field_class(32)
b_fc = self._tc.create_string_field_class()
- c_fc = self._tc.create_real_field_class()
+ c_fc = self._tc.create_single_precision_real_field_class()
self._fc.append_option('c', c_fc, self._ranges1)
self._fc.append_option('a', a_fc, self._ranges2)
self._fc.append_option('b', b_fc, self._ranges3)
# } variant;
# } inner_struct[2];
# };
- self._fc.append_option('a', self._tc.create_real_field_class(), self._ranges1)
+ self._fc.append_option(
+ 'a', self._tc.create_single_precision_real_field_class(), self._ranges1
+ )
self._fc.append_option(
'b', self._tc.create_signed_integer_field_class(21), self._ranges2
)
'c', self._tc.create_unsigned_integer_field_class(34), self._ranges3
)
- foo_fc = self._tc.create_real_field_class()
+ foo_fc = self._tc.create_single_precision_real_field_class()
bar_fc = self._tc.create_string_field_class()
baz_fc = self._tc.create_string_field_class()
fc = self._tc.create_dynamic_array_field_class(self._elem_fc, self._len_fc)
- foo_fc = self._tc.create_real_field_class()
+ foo_fc = self._tc.create_single_precision_real_field_class()
bar_fc = self._tc.create_string_field_class()
baz_fc = self._tc.create_string_field_class()
def test_has__RealField(self):
self._assert_in_bt2('_RealField')
+ def test_has__SinglePrecisionRealField(self):
+ self._assert_in_bt2('_SinglePrecisionRealField')
+
+ def test_has__DoublePrecisionRealField(self):
+ self._assert_in_bt2('_DoublePrecisionRealField')
+
def test_has__EnumerationField(self):
self._assert_in_bt2('_EnumerationField')
def test_has__RealFieldConst(self):
self._assert_in_bt2('_RealFieldConst')
+ def test_has__SinglePrecisionRealFieldConst(self):
+ self._assert_in_bt2('_SinglePrecisionRealFieldConst')
+
+ def test_has__DoublePrecisionRealFieldConst(self):
+ self._assert_in_bt2('_DoublePrecisionRealFieldConst')
+
def test_has__EnumerationFieldConst(self):
self._assert_in_bt2('_EnumerationFieldConst')
sec = tc.create_structure_field_class()
sec += [
('cpu_id', tc.create_signed_integer_field_class(8)),
- ('stuff', tc.create_real_field_class()),
+ ('stuff', tc.create_double_precision_real_field_class()),
]
# packet context
pc = tc.create_structure_field_class()
pc += [
('something', tc.create_signed_integer_field_class(8)),
- ('something_else', tc.create_real_field_class()),
+ ('something_else', tc.create_double_precision_real_field_class()),
('events_discarded', tc.create_unsigned_integer_field_class(64)),
('packet_seq_num', tc.create_unsigned_integer_field_class(64)),
]
Origin is Unix epoch: No
Event class `ev` (ID 0):
Payload field class: Structure (1 member):
- dbl: Real (Double precision)
+ dbl: Double-precision real
[Unknown]
{Trace 0, Stream class ID 0, Stream ID 0}
Origin is Unix epoch: No
Event class `ev` (ID 0):
Payload field class: Structure (1 member):
- flt: Real (Single precision)
+ flt: Single-precision real
[Unknown]
{Trace 0, Stream class ID 0, Stream ID 0}
seqfield_network_3: Dynamic array (Length field path [Event payload: 17]):
Element: Signed integer (64-bit, Base 10)
stringfield: String
- floatfield: Real (Single precision)
- doublefield: Real (Double precision)
+ floatfield: Single-precision real
+ doublefield: Double-precision real
boolfield: Unsigned integer (8-bit, Base 10)
Event class `ust_tests_hello:tptest_sighandler` (ID 26):
Log level: Debug (line)
seqfield_network_3: Dynamic array (Length field path [Event payload: 17]):
Element: Signed integer (64-bit, Base 10)
stringfield: String
- floatfield: Real (Single precision)
- doublefield: Real (Double precision)
+ floatfield: Single-precision real
+ doublefield: Double-precision real
boolfield: Unsigned integer (8-bit, Base 10)
Event class `ust_tests_hello:tptest_sighandler` (ID 26):
Log level: Debug (line)