|
| 1 | +/**************************************************************************/ |
| 2 | +/*! |
| 3 | + @file IEEE11073float.h |
| 4 | +*/ |
| 5 | +/**************************************************************************/ |
| 6 | + |
| 7 | +/** |
| 8 | + * \file bytelib.c |
| 9 | + * \brief Byte manipulation module implementation. |
| 10 | + * Copyright (C) 2010 Signove Tecnologia Corporation. |
| 11 | + * All rights reserved. |
| 12 | + * Contact: Signove Tecnologia Corporation ([email protected]) |
| 13 | + * |
| 14 | + * $LICENSE_TEXT:BEGIN$ |
| 15 | + * This library is free software; you can redistribute it and/or |
| 16 | + * modify it under the terms of the GNU Lesser General Public |
| 17 | + * License as published by the Free Software Foundation and appearing |
| 18 | + * in the file LICENSE included in the packaging of this file; either |
| 19 | + * version 2.1 of the License, or (at your option) any later version. |
| 20 | + * |
| 21 | + * This library is distributed in the hope that it will be useful, |
| 22 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 24 | + * Lesser General Public License for more details. |
| 25 | + * |
| 26 | + * You should have received a copy of the GNU Lesser General Public |
| 27 | + * License along with this library; if not, write to the Free Software |
| 28 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 29 | + * $LICENSE_TEXT:END$ |
| 30 | + * |
| 31 | + * \author Walter Guerra, Mateus Lima |
| 32 | + * \date Jun 14, 2010 |
| 33 | + */ |
| 34 | + |
| 35 | +#ifndef _IEEE11073FLOAT_H_ |
| 36 | +#define _IEEE11073FLOAT_H_ |
| 37 | + |
| 38 | +#include <stdint.h> |
| 39 | + |
| 40 | +typedef enum { |
| 41 | + MDER_POSITIVE_INFINITY = 0x007FFFFE, |
| 42 | + MDER_NaN = 0x007FFFFF, |
| 43 | + MDER_NRes = 0x00800000, |
| 44 | + MDER_RESERVED_VALUE = 0x00800001, |
| 45 | + MDER_NEGATIVE_INFINITY = 0x00800002 |
| 46 | +} ReservedFloatValues; |
| 47 | +static const int32_t FIRST_RESERVED_VALUE = MDER_POSITIVE_INFINITY; |
| 48 | + |
| 49 | +// (2 ** 23 - 3) |
| 50 | +#define MDER_FLOAT_MANTISSA_MAX 0x007FFFFD |
| 51 | +// 2 ** 7 - 1 |
| 52 | +#define MDER_FLOAT_EXPONENT_MAX 127 |
| 53 | +#define MDER_FLOAT_EXPONENT_MIN -128 |
| 54 | +// (2 ** 23 - 3) * 10 ** 127 |
| 55 | +#define MDER_FLOAT_MAX 8.388604999999999e+133 |
| 56 | +// -(2 ** 23 - 3) * 10 ** 127 |
| 57 | +#define MDER_FLOAT_MIN (-MDER_FLOAT_MAX) |
| 58 | +// 10 ** -128 |
| 59 | +#define MDER_FLOAT_EPSILON 1e-128 |
| 60 | +// 10 ** upper(23 * log(2) / log(10)) |
| 61 | +// precision for a number 1.0000xxx |
| 62 | +#define MDER_FLOAT_PRECISION 10000000 |
| 63 | + |
| 64 | +typedef enum { |
| 65 | + MDER_S_POSITIVE_INFINITY = 0x07FE, |
| 66 | + MDER_S_NaN = 0x07FF, |
| 67 | + MDER_S_NRes = 0x0800, |
| 68 | + MDER_S_RESERVED_VALUE = 0x0801, |
| 69 | + MDER_S_NEGATIVE_INFINITY = 0x0802 |
| 70 | +} ReservedSFloatValues; |
| 71 | +static const uint32_t FIRST_S_RESERVED_VALUE = MDER_S_POSITIVE_INFINITY; |
| 72 | + |
| 73 | +// (2 ** 11 - 3) |
| 74 | +#define MDER_SFLOAT_MANTISSA_MAX 0x07FD |
| 75 | +// 2 ** 3 - 1 |
| 76 | +#define MDER_SFLOAT_EXPONENT_MAX 7 |
| 77 | +#define MDER_SFLOAT_EXPONENT_MIN -8 |
| 78 | +// (2 ** 11 - 3) * 10 ** 7 |
| 79 | +#define MDER_SFLOAT_MAX 20450000000.0 |
| 80 | +// -(2 ** 11 - 3) * 10 ** 7 |
| 81 | +#define MDER_SFLOAT_MIN (-MDER_SFLOAT_MAX) |
| 82 | +// 10 ** -8 |
| 83 | +#define MDER_SFLOAT_EPSILON 1e-8 |
| 84 | +// 10 ** upper(11 * log(2) / log(10)) |
| 85 | +#define MDER_SFLOAT_PRECISION 10000 |
| 86 | + |
| 87 | +uint32_t float2IEEE11073(double data, uint8_t output[4]); |
| 88 | + |
| 89 | +#endif /* _IEEE11073FLOAT_H_ */ |
0 commit comments