1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/* ****************************************************************************
* fxlib/bcd.h -- fxlib's BCD numbers management.
*
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of the 'casiowin/fxlib' module in libcarrot, an
* experimental modular libc project.
*
* This file is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This file is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Lesser Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this file. If not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include <fxlib/cdefs.h>
#if __USE_FXLIB_UNOFFICIAL
__BEGIN_NAMESPACE_FXLIB
__BEGIN_DECLS
/* ************************************************************************* */
/* BCD structures */
/* ************************************************************************* */
/* Storage structure */
# define bcdv_BCDval BCDval
struct tag_BCDval {
unsigned char BCDval[9];
unsigned char _align[3];
};
typedef struct tag_BCDval bcdval_t;
typedef struct tag_BCDval BCDVAL;
/* Internal structure (the structure that is actually used for calculations) */
# define bcd_exponent exponent
# define bcd_sign sign
# define bcd_mantissa mantissa
struct tag_BCD {
int exponent;
int sign;
int _unknown;
char mantissa[15];
};
typedef struct tag_BCD bcd_t;
typedef struct tag_BCD BCD;
/* ************************************************************************* */
/* Methods */
/* ************************************************************************* */
/* BCD to internal */
extern __nonnull(1, __internal) __nonnull(2, __source)
int BCDtoInternal _OF((bcd_t *__internal, const bcdval_t *__source)) __THROW;
/* Conversions from and to unsigned int (FIXME: probably wrong prototypes) */
extern __nonnull(1, __source) __nonnull(2, __dest)
int Num_UIntToBCD _OF((const unsigned int *__source, bcd_t *__dest)) __THROW;
extern __nonnull(1, __dest) __nonnull(2, __source)
int Num_BCDToUint _OF((unsigned int *__dest, bcd_t *__source)) __THROW;
/* calculate an expression */
extern __nonnull(1, __formula) __nonnull(3, __opcode)
void CalculateExpression _OF((char **__formula, char __opcode[2],
bcdval_t *__result, int __copyfirst)) __THROW;
/* get not a number value */
extern __nonnull(1, __value) __nonnull(2, __result)
int BCD_GetNotANumberValue _OF((const unsigned char *__value,
unsigned char *__result)) __THROW;
__END_DECLS
__END_NAMESPACE_FXLIB
#endif
|