aboutsummaryrefslogtreecommitdiffstats
path: root/epan/ftypes/ftype-ieee-11073-float.c
diff options
context:
space:
mode:
Diffstat (limited to 'epan/ftypes/ftype-ieee-11073-float.c')
-rw-r--r--epan/ftypes/ftype-ieee-11073-float.c546
1 files changed, 12 insertions, 534 deletions
diff --git a/epan/ftypes/ftype-ieee-11073-float.c b/epan/ftypes/ftype-ieee-11073-float.c
index 4f5371f4ab..457fc182e4 100644
--- a/epan/ftypes/ftype-ieee-11073-float.c
+++ b/epan/ftypes/ftype-ieee-11073-float.c
@@ -358,192 +358,6 @@ sfloat_ieee_11073_cmp_eq(const fvalue_t *a, const fvalue_t *b)
}
static gboolean
-sfloat_ieee_11073_cmp_ne(const fvalue_t *a, const fvalue_t *b)
-{
- return sfloat_to_normal_form(a->value.sfloat_ieee_11073) != sfloat_to_normal_form(b->value.sfloat_ieee_11073);
-}
-
-static gboolean
-sfloat_ieee_11073_cmp_gt(const fvalue_t *a, const fvalue_t *b)
-{
- guint16 a_norm;
- guint16 b_norm;
- gint16 a_norm_mantissa;
- gint16 b_norm_mantissa;
- gint8 a_norm_exponent;
- gint8 b_norm_exponent;
-
- a_norm = sfloat_to_normal_form(a->value.sfloat_ieee_11073);
- b_norm = sfloat_to_normal_form(b->value.sfloat_ieee_11073);
-
- if (a_norm == b_norm)
- return FALSE;
-
- switch (a_norm) {
- case SFLOAT_VALUE_NAN:
- case SFLOAT_VALUE_NRES:
- case SFLOAT_VALUE_RFU:
- case SFLOAT_VALUE_INFINITY_MINUS:
- return FALSE;
- case SFLOAT_VALUE_INFINITY_PLUS:
- switch (b_norm) {
- case SFLOAT_VALUE_NAN:
- case SFLOAT_VALUE_NRES:
- case SFLOAT_VALUE_RFU:
- case SFLOAT_VALUE_INFINITY_PLUS: /* Dead, informative case */
- return FALSE;
- case SFLOAT_VALUE_INFINITY_MINUS:
- default:
- return TRUE;
- }
- }
-
- a_norm_mantissa = a_norm & 0x0FFF;
- b_norm_mantissa = b_norm & 0x0FFF;
- if (a_norm & 0x0800)
- a_norm_mantissa |= 0xF000;
-
- if (b_norm & 0x0800)
- b_norm_mantissa |= 0xF000;
-
- a_norm_exponent = a_norm >> 12;
- b_norm_exponent = b_norm >> 12;
-
- if (a_norm_exponent & 0x08) {
- a_norm_exponent |= 0xF0;
- }
-
- if (b_norm_exponent & 0x08) {
- b_norm_exponent |= 0xF0;
- }
-
- if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent > b_norm_exponent)
- return TRUE;
-
- if (a_norm_exponent == b_norm_exponent && a_norm_mantissa > b_norm_mantissa)
- return TRUE;
-
- if (a_norm_exponent < b_norm_exponent) {
- guint8 exponent_difference;
-
- exponent_difference = b_norm_exponent - a_norm_exponent;
-
- if (exponent_difference >= 4)
- return FALSE;
-
- while (exponent_difference--) {
- b_norm_mantissa *= 10;
- }
- } else {
- guint8 exponent_difference;
-
- exponent_difference = a_norm_exponent - b_norm_exponent;
-
- if (exponent_difference >= 4)
- return TRUE;
-
- while (exponent_difference--) {
- a_norm_mantissa *= 10;
- }
- }
-
- if (a_norm_mantissa > b_norm_mantissa)
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-sfloat_ieee_11073_cmp_ge(const fvalue_t *a, const fvalue_t *b)
-{
- guint16 a_norm;
- guint16 b_norm;
- gint16 a_norm_mantissa;
- gint16 b_norm_mantissa;
- gint8 a_norm_exponent;
- gint8 b_norm_exponent;
-
- a_norm = sfloat_to_normal_form(a->value.sfloat_ieee_11073);
- b_norm = sfloat_to_normal_form(b->value.sfloat_ieee_11073);
-
- if (a_norm == b_norm)
- return TRUE;
-
- switch (a_norm) {
- case SFLOAT_VALUE_NAN:
- case SFLOAT_VALUE_NRES:
- case SFLOAT_VALUE_RFU:
- case SFLOAT_VALUE_INFINITY_MINUS:
- return FALSE;
- case SFLOAT_VALUE_INFINITY_PLUS:
- switch (b_norm) {
- case SFLOAT_VALUE_NAN:
- case SFLOAT_VALUE_NRES:
- case SFLOAT_VALUE_RFU:
- case SFLOAT_VALUE_INFINITY_PLUS: /* Dead, informative case */
- return FALSE;
- case SFLOAT_VALUE_INFINITY_MINUS:
- default:
- return TRUE;
- }
- }
-
- a_norm_mantissa = a_norm & 0x0FFF;
- b_norm_mantissa = b_norm & 0x0FFF;
- if (a_norm & 0x0800)
- a_norm_mantissa |= 0xF000;
-
- if (b_norm & 0x0800)
- b_norm_mantissa |= 0xF000;
-
- a_norm_exponent = a_norm >> 12;
- b_norm_exponent = b_norm >> 12;
-
- if (a_norm_exponent & 0x08) {
- a_norm_exponent |= 0xF0;
- }
-
- if (b_norm_exponent & 0x08) {
- b_norm_exponent |= 0xF0;
- }
-
- if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent >= b_norm_exponent)
- return TRUE;
-
- if (a_norm_exponent == b_norm_exponent && a_norm_mantissa >= b_norm_mantissa)
- return TRUE;
-
- if (a_norm_exponent < b_norm_exponent) {
- guint8 exponent_difference;
-
- exponent_difference = b_norm_exponent - a_norm_exponent;
-
- if (exponent_difference >= 4)
- return FALSE;
-
- while (exponent_difference--) {
- b_norm_mantissa *= 10;
- }
- } else {
- guint8 exponent_difference;
-
- exponent_difference = a_norm_exponent - b_norm_exponent;
-
- if (exponent_difference >= 4)
- return TRUE;
-
- while (exponent_difference--) {
- a_norm_mantissa *= 10;
- }
- }
-
- if (a_norm_mantissa > b_norm_mantissa)
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
sfloat_ieee_11073_cmp_lt(const fvalue_t *a, const fvalue_t *b)
{
guint16 a_norm;
@@ -633,94 +447,12 @@ sfloat_ieee_11073_cmp_lt(const fvalue_t *a, const fvalue_t *b)
return FALSE;
}
-static gboolean
-sfloat_ieee_11073_cmp_le(const fvalue_t *a, const fvalue_t *b)
+static int
+sfloat_ieee_11073_cmp_order(const fvalue_t *a, const fvalue_t *b)
{
- guint16 a_norm;
- guint16 b_norm;
- gint16 a_norm_mantissa;
- gint16 b_norm_mantissa;
- gint8 a_norm_exponent;
- gint8 b_norm_exponent;
-
- a_norm = sfloat_to_normal_form(a->value.sfloat_ieee_11073);
- b_norm = sfloat_to_normal_form(b->value.sfloat_ieee_11073);
-
- if (a_norm == b_norm)
- return TRUE;
-
- switch (a_norm) {
- case SFLOAT_VALUE_NAN:
- case SFLOAT_VALUE_NRES:
- case SFLOAT_VALUE_RFU:
- case SFLOAT_VALUE_INFINITY_PLUS:
- return FALSE;
- case SFLOAT_VALUE_INFINITY_MINUS:
- switch (b_norm) {
- case SFLOAT_VALUE_NAN:
- case SFLOAT_VALUE_NRES:
- case SFLOAT_VALUE_RFU:
- case SFLOAT_VALUE_INFINITY_MINUS: /* Dead, informative case */
- return FALSE;
- case SFLOAT_VALUE_INFINITY_PLUS:
- default:
- return TRUE;
- }
- }
-
- a_norm_mantissa = a_norm & 0x0FFF;
- b_norm_mantissa = b_norm & 0x0FFF;
- if (a_norm & 0x0800)
- a_norm_mantissa |= 0xF000;
-
- if (b_norm & 0x0800)
- b_norm_mantissa |= 0xF000;
-
- a_norm_exponent = a_norm >> 12;
- b_norm_exponent = b_norm >> 12;
-
- if (a_norm_exponent & 0x08) {
- a_norm_exponent |= 0xF0;
- }
-
- if (b_norm_exponent & 0x08) {
- b_norm_exponent |= 0xF0;
- }
-
- if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent <= b_norm_exponent)
- return TRUE;
-
- if (a_norm_exponent == b_norm_exponent && a_norm_mantissa <= b_norm_mantissa)
- return TRUE;
-
- if (a_norm_exponent < b_norm_exponent) {
- guint8 exponent_difference;
-
- exponent_difference = b_norm_exponent - a_norm_exponent;
-
- if (exponent_difference >= 4)
- return TRUE;
-
- while (exponent_difference--) {
- b_norm_mantissa *= 10;
- }
- } else {
- guint8 exponent_difference;
-
- exponent_difference = a_norm_exponent - b_norm_exponent;
-
- if (exponent_difference >= 4)
- return FALSE;
-
- while (exponent_difference--) {
- a_norm_mantissa *= 10;
- }
- }
-
- if (a_norm_mantissa < b_norm_mantissa)
- return TRUE;
-
- return FALSE;
+ if (sfloat_ieee_11073_cmp_lt(a, b))
+ return -1;
+ return sfloat_ieee_11073_cmp_eq(a, b) ? 0 : 1;
}
static gboolean
@@ -1046,176 +778,6 @@ float_ieee_11073_cmp_eq(const fvalue_t *a, const fvalue_t *b)
}
static gboolean
-float_ieee_11073_cmp_ne(const fvalue_t *a, const fvalue_t *b)
-{
- return float_to_normal_form(a->value.float_ieee_11073) != float_to_normal_form(b->value.float_ieee_11073);
-}
-
-static gboolean
-float_ieee_11073_cmp_gt(const fvalue_t *a, const fvalue_t *b)
-{
- guint32 a_norm;
- guint32 b_norm;
- gint32 a_norm_mantissa;
- gint32 b_norm_mantissa;
- gint8 a_norm_exponent;
- gint8 b_norm_exponent;
-
- a_norm = float_to_normal_form(a->value.float_ieee_11073);
- b_norm = float_to_normal_form(b->value.float_ieee_11073);
-
- if (a_norm == b_norm)
- return FALSE;
-
- switch (a_norm) {
- case FLOAT_VALUE_NAN:
- case FLOAT_VALUE_NRES:
- case FLOAT_VALUE_RFU:
- case FLOAT_VALUE_INFINITY_MINUS:
- return FALSE;
- case FLOAT_VALUE_INFINITY_PLUS:
- switch (b_norm) {
- case FLOAT_VALUE_NAN:
- case FLOAT_VALUE_NRES:
- case FLOAT_VALUE_RFU:
- case FLOAT_VALUE_INFINITY_PLUS: /* Dead, informative case */
- return FALSE;
- case FLOAT_VALUE_INFINITY_MINUS:
- default:
- return TRUE;
- }
- }
-
- a_norm_mantissa = a_norm & 0x00FFFFFF;
- b_norm_mantissa = b_norm & 0x00FFFFFF;
- if (a_norm & 0x00800000)
- a_norm_mantissa |= 0xFF000000;
-
- if (b_norm & 0x00800000)
- b_norm_mantissa |= 0xFF000000;
-
- a_norm_exponent = a_norm >> 24;
- b_norm_exponent = b_norm >> 24;
-
- if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent > b_norm_exponent)
- return TRUE;
-
- if (a_norm_exponent == b_norm_exponent && a_norm_mantissa > b_norm_mantissa)
- return TRUE;
-
- if (a_norm_exponent < b_norm_exponent) {
- guint8 exponent_difference;
-
- exponent_difference = b_norm_exponent - a_norm_exponent;
-
- if (exponent_difference >= 7)
- return FALSE;
-
- while (exponent_difference--) {
- b_norm_mantissa *= 10;
- }
- } else {
- guint8 exponent_difference;
-
- exponent_difference = a_norm_exponent - b_norm_exponent;
-
- if (exponent_difference >= 7)
- return TRUE;
-
- while (exponent_difference--) {
- a_norm_mantissa *= 10;
- }
- }
-
- if (a_norm_mantissa > b_norm_mantissa)
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-float_ieee_11073_cmp_ge(const fvalue_t *a, const fvalue_t *b)
-{
- guint32 a_norm;
- guint32 b_norm;
- gint32 a_norm_mantissa;
- gint32 b_norm_mantissa;
- gint8 a_norm_exponent;
- gint8 b_norm_exponent;
-
- a_norm = float_to_normal_form(a->value.float_ieee_11073);
- b_norm = float_to_normal_form(b->value.float_ieee_11073);
-
- if (a_norm == b_norm)
- return TRUE;
-
- switch (a_norm) {
- case FLOAT_VALUE_NAN:
- case FLOAT_VALUE_NRES:
- case FLOAT_VALUE_RFU:
- case FLOAT_VALUE_INFINITY_MINUS:
- return FALSE;
- case FLOAT_VALUE_INFINITY_PLUS:
- switch (b_norm) {
- case FLOAT_VALUE_NAN:
- case FLOAT_VALUE_NRES:
- case FLOAT_VALUE_RFU:
- case FLOAT_VALUE_INFINITY_PLUS: /* Dead, informative case */
- return FALSE;
- case FLOAT_VALUE_INFINITY_MINUS:
- default:
- return TRUE;
- }
- }
-
- a_norm_mantissa = a_norm & 0x00FFFFFF;
- b_norm_mantissa = b_norm & 0x00FFFFFF;
- if (a_norm & 0x00800000)
- a_norm_mantissa |= 0xFF000000;
-
- if (b_norm & 0x00800000)
- b_norm_mantissa |= 0xFF000000;
-
- a_norm_exponent = a_norm >> 24;
- b_norm_exponent = b_norm >> 24;
-
- if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent >= b_norm_exponent)
- return TRUE;
-
- if (a_norm_exponent == b_norm_exponent && a_norm_mantissa >= b_norm_mantissa)
- return TRUE;
-
- if (a_norm_exponent < b_norm_exponent) {
- guint8 exponent_difference;
-
- exponent_difference = b_norm_exponent - a_norm_exponent;
-
- if (exponent_difference >= 7)
- return FALSE;
-
- while (exponent_difference--) {
- b_norm_mantissa *= 10;
- }
- } else {
- guint8 exponent_difference;
-
- exponent_difference = a_norm_exponent - b_norm_exponent;
-
- if (exponent_difference >= 7)
- return TRUE;
-
- while (exponent_difference--) {
- a_norm_mantissa *= 10;
- }
- }
-
- if (a_norm_mantissa > b_norm_mantissa)
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
float_ieee_11073_cmp_lt(const fvalue_t *a, const fvalue_t *b)
{
guint32 a_norm;
@@ -1297,86 +859,12 @@ float_ieee_11073_cmp_lt(const fvalue_t *a, const fvalue_t *b)
return FALSE;
}
-static gboolean
-float_ieee_11073_cmp_le(const fvalue_t *a, const fvalue_t *b)
+static int
+float_ieee_11073_cmp_order(const fvalue_t *a, const fvalue_t *b)
{
- guint32 a_norm;
- guint32 b_norm;
- gint32 a_norm_mantissa;
- gint32 b_norm_mantissa;
- gint8 a_norm_exponent;
- gint8 b_norm_exponent;
-
- a_norm = float_to_normal_form(a->value.float_ieee_11073);
- b_norm = float_to_normal_form(b->value.float_ieee_11073);
-
- if (a_norm == b_norm)
- return TRUE;
-
- switch (a_norm) {
- case FLOAT_VALUE_NAN:
- case FLOAT_VALUE_NRES:
- case FLOAT_VALUE_RFU:
- case FLOAT_VALUE_INFINITY_PLUS:
- return FALSE;
- case FLOAT_VALUE_INFINITY_MINUS:
- switch (b_norm) {
- case FLOAT_VALUE_NAN:
- case FLOAT_VALUE_NRES:
- case FLOAT_VALUE_RFU:
- case FLOAT_VALUE_INFINITY_MINUS: /* Dead, informative case */
- return FALSE;
- case FLOAT_VALUE_INFINITY_PLUS:
- default:
- return TRUE;
- }
- }
-
- a_norm_mantissa = a_norm & 0x00FFFFFF;
- b_norm_mantissa = b_norm & 0x00FFFFFF;
- if (a_norm & 0x00800000)
- a_norm_mantissa |= 0xFF000000;
-
- if (b_norm & 0x00800000)
- b_norm_mantissa |= 0xFF000000;
-
- a_norm_exponent = a_norm >> 24;
- b_norm_exponent = b_norm >> 24;
-
- if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent <= b_norm_exponent)
- return TRUE;
-
- if (a_norm_exponent == b_norm_exponent && a_norm_mantissa <= b_norm_mantissa)
- return TRUE;
-
- if (a_norm_exponent < b_norm_exponent) {
- guint8 exponent_difference;
-
- exponent_difference = b_norm_exponent - a_norm_exponent;
-
- if (exponent_difference >= 7)
- return TRUE;
-
- while (exponent_difference--) {
- b_norm_mantissa *= 10;
- }
- } else {
- guint8 exponent_difference;
-
- exponent_difference = a_norm_exponent - b_norm_exponent;
-
- if (exponent_difference >= 7)
- return FALSE;
-
- while (exponent_difference--) {
- a_norm_mantissa *= 10;
- }
- }
-
- if (a_norm_mantissa < b_norm_mantissa)
- return TRUE;
-
- return FALSE;
+ if (float_ieee_11073_cmp_lt(a, b))
+ return -1;
+ return float_ieee_11073_cmp_eq(a, b) ? 0 : 1;
}
static gboolean
@@ -1431,12 +919,7 @@ Example: 114 is 0x0072
{ .set_value_uinteger = sfloat_ieee_11073_value_set }, /* union set_value */
{ .get_value_uinteger = sfloat_ieee_11073_value_get }, /* union get_value */
- sfloat_ieee_11073_cmp_eq,
- sfloat_ieee_11073_cmp_ne,
- sfloat_ieee_11073_cmp_gt,
- sfloat_ieee_11073_cmp_ge,
- sfloat_ieee_11073_cmp_lt,
- sfloat_ieee_11073_cmp_le,
+ sfloat_ieee_11073_cmp_order,
sfloat_ieee_11073_cmp_bitwise_and, /* cmp_bitwise_and */
NULL, /* cmp_contains */
NULL, /* cmp_matches */
@@ -1487,12 +970,7 @@ Example: 36.4 is 0xFF00016C
{ .set_value_uinteger = float_ieee_11073_value_set }, /* union set_value */
{ .get_value_uinteger = float_ieee_11073_value_get }, /* union get_value */
- float_ieee_11073_cmp_eq,
- float_ieee_11073_cmp_ne,
- float_ieee_11073_cmp_gt,
- float_ieee_11073_cmp_ge,
- float_ieee_11073_cmp_lt,
- float_ieee_11073_cmp_le,
+ float_ieee_11073_cmp_order,
float_ieee_11073_cmp_bitwise_and, /* cmp_bitwise_and */
NULL, /* cmp_contains */
NULL, /* cmp_matches */