mirror of
https://gitee.com/Lamdonn/varch.git
synced 2026-01-01 03:12:08 +08:00
1. Add math category folder
2. Add the floatl initial version 3. Add the intl_print function 4. Fix intl_from issue 5. Add intl unit test code
This commit is contained in:
parent
660bc06f97
commit
fa4bd85f2e
@ -2,7 +2,7 @@
|
||||
|
||||

|
||||
|
||||
[](https://gitee.com/Lamdonn/varch)
|
||||
[](https://gitee.com/Lamdonn/varch)
|
||||
[](LICENSE)
|
||||
[](Lamdonn@163.com)
|
||||

|
||||
@ -18,7 +18,7 @@ It has the characteristics of **simplicity, universality, and efficiency**, with
|
||||
|
||||
| module | version | usage | path | describe |
|
||||
|:-------------|:---------|:-----------------------------|:------------------------------------------|:--------------------------------------|
|
||||
| overall | 00.03.00 | [link](README.en.md) | [path](./) | Overall
|
||||
| overall | 00.03.01 | [link](README.en.md) | [path](./) | Overall
|
||||
| init | 01.00.00 | [link](/doc/init.en.md) | [path](./source/00_application) | Initialize export module
|
||||
| console | 01.00.01 | [link](/doc/console.en.md) | [path](./source/00_application/console) | Console command input, combined with the 'command' module, parsing commands entered in the console
|
||||
| arg | 01.00.00 | [link](/doc/arg.en.md) | [path](./source/01_general) | Indefinite parameters, obtain the number of indefinite parameters and specified parameters
|
||||
@ -72,6 +72,8 @@ It has the characteristics of **simplicity, universality, and efficiency**, with
|
||||
| romt | 01.00.00 | [link](/doc/romt.en.md) | [path](./source/06_performance) | ROM test module
|
||||
| cpul | 01.00.00 | [link](/doc/cpul.en.md) | [path](./source/06_performance) | CPU load test module, including obtaining and increasing load
|
||||
| unitt | 01.00.00 | [link](/doc/unitt.en.md) | [path](./source/06_performance) | Simple unit test module
|
||||
| intl | 01.00.00 | [link](/doc/intl.en.md) | [path](./source/07_math) | Large integer arithmetic module
|
||||
| floatl | 01.00.00 | [link](/doc/floatl.en.md) | [path](./source/07_math) | Large floating-point arithmetic module
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||

|
||||
|
||||
[](https://gitee.com/Lamdonn/varch)
|
||||
[](https://gitee.com/Lamdonn/varch)
|
||||
[](LICENSE)
|
||||
[](Lamdonn@163.com)
|
||||

|
||||
@ -18,7 +18,7 @@ varch(we-architecture,意为我们的框架库)是嵌入式C语言常用
|
||||
|
||||
| module | version | usage | path | describe |
|
||||
|:-------------|:---------|:-----------------------------|:------------------------------------------|:--------------------------------------|
|
||||
| overall | 00.03.00 | [link](README.md) | [path](./) | 整体
|
||||
| overall | 00.03.01 | [link](README.md) | [path](./) | 整体
|
||||
| init | 01.00.00 | [link](/doc/init.md) | [path](./source/00_application) | 初始化导出模块
|
||||
| console | 01.00.01 | [link](/doc/console.md) | [path](./source/00_application/console) | 控制台命令输入,结合 `command` 模块,解析在控制台中输入的命令
|
||||
| arg | 01.00.00 | [link](/doc/arg.md) | [path](./source/01_general) | 不定参数,获取不定参数和指定参数的个数
|
||||
@ -72,6 +72,8 @@ varch(we-architecture,意为我们的框架库)是嵌入式C语言常用
|
||||
| romt | 01.00.00 | [link](/doc/romt.md) | [path](./source/06_performance) | ROM测试模块
|
||||
| cpul | 01.00.00 | [link](/doc/cpul.md) | [path](./source/06_performance) | CPU负载测试模块,包含获取和增加负载
|
||||
| unitt | 01.00.00 | [link](/doc/unitt.md) | [path](./source/06_performance) | 简易的单元测试模块
|
||||
| intl | 01.00.00 | [link](/doc/intl.md) | [path](./source/07_math) | 大型整数运算模块
|
||||
| floatl | 01.00.00 | [link](/doc/floatl.md) | [path](./source/07_math) | 大型浮点数运算模块
|
||||
|
||||
## 使用说明
|
||||
|
||||
|
||||
181
doc/floatl.en.md
Normal file
181
doc/floatl.en.md
Normal file
@ -0,0 +1,181 @@
|
||||
## Introduction
|
||||
|
||||
`floatl` is a large floating-point number module that allows operations on large floating-point numbers exceeding the limits of standard C language data types. It provides a flexible long-integer representation, using 16-bit and 32-bit segments for storage.
|
||||
|
||||
In current mainstream computer systems, the maximum integer types generally supported are 32-bit or 64-bit integers, which can meet the computational and storage requirements in general cases. However, they become inadequate when dealing with larger numbers.
|
||||
|
||||
As an additional extension for floating-point numbers, the `floatl` module adopts a storage mechanism consistent with `IEEE 754` and is very convenient to use. It supports the following calculations:
|
||||
|
||||
- Basic arithmetic operations: addition, subtraction, multiplication, and division.
|
||||
- Functions to convert strings and standard floating-point numbers to large floating-point numbers.
|
||||
- Functions to output large floating-point numbers in decimal, `[P-]`, and `[E-]` formats.
|
||||
|
||||
`floatl` can be configured as 64-bit, 128-bit, 256-bit, 512-bit, 1024-bit, 2048-bit, 4096-bit, or 8192-bit as needed. If these configurations are still insufficient, it also provides functions to generate larger bit configurations.
|
||||
|
||||
## Interfaces
|
||||
|
||||
### Structure Definitions
|
||||
|
||||
#### `floatl`
|
||||
|
||||
A structure used to represent long-integer floating-point numbers, using a union to store floating-point numbers in two different ways:
|
||||
|
||||
- An array of `uint16_t` type (16-bit segments).
|
||||
- An array of `uint32_t` type (32-bit segments).
|
||||
|
||||
```c
|
||||
typedef struct {
|
||||
union {
|
||||
uint16_t u16[__FLOATL_U16_PARTS__]; ///< Array of uint16_t values representing the long bit integer in 16-bit segments.
|
||||
uint32_t u32[__FLOATL_U32_PARTS__]; ///< Array of uint32_t values representing the long bit integer in 32-bit segments.
|
||||
struct {
|
||||
uint32_t mantissas[__FLOATL_MANT_PARTS__];
|
||||
uint32_t mantissa : __FLOATL_MANT_HIGH_BITS__;
|
||||
uint32_t exponent : __FLOATL_EXP_BITS__;
|
||||
uint32_t sign : 1;
|
||||
};
|
||||
};
|
||||
} floatl;
|
||||
```
|
||||
|
||||
### Definition Functions
|
||||
|
||||
```c
|
||||
floatl floatl_from(const char *str);
|
||||
floatl floatl_from_f(float value);
|
||||
floatl floatl_from_d(double value);
|
||||
```
|
||||
|
||||
`floatl` provides two types of definition functions.
|
||||
|
||||
`floatl_from` parses a `floatl` from a numeric string and supports parsing strings in decimal, `[P-]`, and `[E-]` formats.
|
||||
`floatl_from_f` creates a `floatl` from a `float` type.
|
||||
`floatl_from_d` creates a `floatl` from a `double` type. This function is encapsulated into a shorter macro definition `floatl()`, which is more in line with usage habits and has higher execution efficiency.
|
||||
|
||||
When using these three functions, if the value is within the range of `double`, it is recommended to use the `floatl()` method. When the value exceeds the range of `double` or when different number systems are required for definition, the `floatl_from` method can be used.
|
||||
|
||||
Meanwhile, you can also use the macro definitions of common values such as `FLOATL_INF`, `FLOATL_NAN`, `FLOATL_CONST_0`, `FLOATL_CONST_1`, `FLOATL_CONST_10`, etc.
|
||||
|
||||
Example:
|
||||
```c
|
||||
static void test_define(void)
|
||||
{
|
||||
floatl a = floatl(0.0);
|
||||
floatl b = floatl(10.0);
|
||||
floatl c = floatl(-3.14);
|
||||
floatl d = floatl(1.23456789e+10);
|
||||
floatl e = floatl(0x1.23456789p+10);
|
||||
|
||||
floatl f = floatl_from("0.0");
|
||||
floatl g = floatl_from("10.0");
|
||||
floatl h = floatl_from("-3.14");
|
||||
floatl i = floatl_from("1.23456789e+10");
|
||||
floatl j = floatl_from("0x1.23456789p+10");
|
||||
|
||||
floatl zero = FLOATL_CONST_0;
|
||||
floatl one = FLOATL_CONST_1;
|
||||
floatl ten = FLOATL_CONST_10;
|
||||
|
||||
printf("size %d\r\n", sizeof(floatl));
|
||||
}
|
||||
```
|
||||
|
||||
### Conversion Functions
|
||||
|
||||
```c
|
||||
int floatl_print(floatl a, char *buffer, uint32_t size, const char *format);
|
||||
#define floatl_show(a, b, s, f) (floatl_print((a), (b), (s), (f)) > 0 ? (b) : "invalid")
|
||||
```
|
||||
|
||||
This function converts the value of `a` into decimal, `[P-]`, and `[E-]` formats according to the specified format and stores the result in the passed `buffer`. It then returns the address of the valid part of the `buffer`.
|
||||
`buffer` and `size` are the address and size of the buffer used to store the conversion result, respectively.
|
||||
`format` is similar to that used in `printf`, with the format ```[flags][width][type]```, such as `0.2f`, `+5.2a`, etc.
|
||||
|
||||
```c
|
||||
static void test_print(void)
|
||||
{
|
||||
floatl a = floatl_from("1234567890.123456789");
|
||||
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%f"));
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%.2f"));
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%020.2f"));
|
||||
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%+.6a"));
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%+20.6a"));
|
||||
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%-20.6e"));
|
||||
}
|
||||
```
|
||||
|
||||
Results:
|
||||
```
|
||||
a 1234567890.123451
|
||||
a 1234567890.12
|
||||
a 00000001234567890.12
|
||||
a +0x1.26580bp+30
|
||||
a +0x1.26580bp+30
|
||||
a 1.234568e+009
|
||||
```
|
||||
|
||||
### Arithmetic Functions
|
||||
|
||||
```c
|
||||
floatl floatl_add(floatl a, floatl b); // a+b
|
||||
floatl floatl_sub(floatl a, floatl b); // a-b
|
||||
floatl floatl_mul(floatl a, floatl b); // a*b
|
||||
floatl floatl_div(floatl a, floatl b); // a/b
|
||||
floatl floatl_abs(floatl a); // |a|
|
||||
floatl floatl_neg(floatl a); // -a
|
||||
int floatl_eq(floatl a, floatl b); // a<b
|
||||
int floatl_ne(floatl a, floatl b); // a<=b
|
||||
int floatl_lt(floatl a, floatl b); // a==b
|
||||
int floatl_le(floatl a, floatl b); // a!=b
|
||||
int floatl_gt(floatl a, floatl b); // a>b
|
||||
int floatl_ge(floatl a, floatl b); // a>=b
|
||||
```
|
||||
|
||||
The arithmetic functions of `floatl` are consistent with the corresponding symbolic operations.
|
||||
|
||||
Usage example:
|
||||
```c
|
||||
static void test_calculate(void)
|
||||
{
|
||||
floatl a = floatl_from("123456789.123456789");
|
||||
floatl b = floatl_from("987654321.987654321");
|
||||
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%f"));
|
||||
printf("b %s\r\n", floatl_show(b, buffer, sizeof(buffer), "%f"));
|
||||
|
||||
printf("a + b: %s\r\n", floatl_show(floatl_add(a, b), buffer, sizeof(buffer), "%f"));
|
||||
printf("a - b: %s\r\n", floatl_show(floatl_sub(a, b), buffer, sizeof(buffer), "%f"));
|
||||
printf("a * b: %s\r\n", floatl_show(floatl_mul(a, b), buffer, sizeof(buffer), "%f"));
|
||||
printf("b / a: %s\r\n", floatl_show(floatl_div(a, b), buffer, sizeof(buffer), "%f"));
|
||||
printf("-a: %s\r\n", floatl_show(floatl_neg(a), buffer, sizeof(buffer), "%f"));
|
||||
printf("|a|: %s\r\n", floatl_show(floatl_abs(a), buffer, sizeof(buffer), "%f"));
|
||||
printf("a > b: %d\r\n", floatl_gt(a, b));
|
||||
printf("a >= b: %d\r\n", floatl_ge(a, b));
|
||||
printf("a < b: %d\r\n", floatl_lt(a, b));
|
||||
printf("a <= b: %d\r\n", floatl_le(a, b));
|
||||
printf("a == b: %d\r\n", floatl_eq(a, b));
|
||||
printf("a != b: %d\r\n", floatl_ne(a, b));
|
||||
}
|
||||
```
|
||||
|
||||
Results:
|
||||
```
|
||||
a 123456789.123456
|
||||
b 987654321.987650
|
||||
a + b: 1111111111.111118
|
||||
a - b: -864197532.864200
|
||||
a * b: 121932631356500755.185485
|
||||
b / a: 0.125000
|
||||
-a: -123456789.123456
|
||||
|a|: 123456789.123456
|
||||
a > b: 0
|
||||
a >= b: 0
|
||||
a < b: 1
|
||||
a <= b: 1
|
||||
a == b: 0
|
||||
a != b: 1
|
||||
```
|
||||
|
||||
181
doc/floatl.md
Normal file
181
doc/floatl.md
Normal file
@ -0,0 +1,181 @@
|
||||
## 介绍
|
||||
|
||||
`floatl`为一个大型浮点数模块,该模块允许对超过 C 语言标准数据类型限制的大浮点数进行操作。它提供了一个灵活的长整型表示,使用 16 位和 32 位段来存储。
|
||||
|
||||
现在主流的计算机系统中一般支持的最大整形数为 32bits 或者 64bits 的,其能满足在一般情况下的计算及存储,但是面对一些更大的数时候就会显得有心无力。
|
||||
而`floatl`模块作为额外的浮点数扩充,采用了与 `IEEE 754` 一致的存储机制,而且在使用起来也非常方便。提供以下的计算:
|
||||
|
||||
- 支持基本算术操作:加法、减法、乘法、除法。
|
||||
- 将字符串和标准浮点数转换为大浮点数的功能。
|
||||
- 提供以十进制、`[P-]` 和 `[E-]`格式输出大浮点数的函数。
|
||||
|
||||
`floatl` 可以按需配置为 64bits、128bits、256bits、512bits、1024bits、2048bits、4096bits、8192bits,如果都还不满足,还提供了生成更大bits的函数来生成更大的配置。
|
||||
|
||||
|
||||
## 接口
|
||||
|
||||
## 结构定义
|
||||
|
||||
### `floatl`
|
||||
|
||||
一个结构体,用于表示长整型浮点数,使用联合体以两种不同方式存储浮点数:
|
||||
|
||||
- 一个 `uint16_t` 类型的数组(16 位段)。
|
||||
- 一个 `uint32_t` 类型的数组(32 位段)。
|
||||
|
||||
```c
|
||||
typedef struct {
|
||||
union {
|
||||
uint16_t u16[__FLOATL_U16_PARTS__]; ///< Array of uint16_t values representing the long bit integer in 16-bit segments.
|
||||
uint32_t u32[__FLOATL_U32_PARTS__]; ///< Array of uint32_t values representing the long bit integer in 32-bit segments.
|
||||
struct {
|
||||
uint32_t mantissas[__FLOATL_MANT_PARTS__];
|
||||
uint32_t mantissa : __FLOATL_MANT_HIGH_BITS__;
|
||||
uint32_t exponent : __FLOATL_EXP_BITS__;
|
||||
uint32_t sign : 1;
|
||||
};
|
||||
};
|
||||
} floatl;
|
||||
```
|
||||
|
||||
### 定义函数
|
||||
|
||||
```c
|
||||
floatl floatl_from(const char *str);
|
||||
floatl floatl_from_f(float value);
|
||||
floatl floatl_from_d(double value);
|
||||
```
|
||||
|
||||
`floatl`提供了两种定义函数。
|
||||
|
||||
`floatl_from`为从数字字符串中解析生成一个`floatl`,支持解析十进制、`[P-]` 和 `[E-]`格式字符串。
|
||||
`floatl_from_f`为从`float`型中创建一个`floatl`。
|
||||
`floatl_from_d`为从`double`型中创建一个`floatl`,此函数封装成更简短的宏定义方法`floatl()`更贴近使用习惯,此方法执行效率更高。
|
||||
|
||||
三者的使用,当值在`double`的取值范围内时,推荐使用`floatl()`方法,而当数值超越`double`的取值范围时或者需要不同进制进行定义时,就可以使用`floatl_from`方法。
|
||||
|
||||
同时,也可以使用常用值的宏定义`FLOATL_INF`、`FLOATL_NAN`、`FLOATL_CONST_0`、`FLOATL_CONST_1`、`FLOATL_CONST_10`等。
|
||||
|
||||
例子:
|
||||
```c
|
||||
static void test_define(void)
|
||||
{
|
||||
floatl a = floatl(0.0);
|
||||
floatl b = floatl(10.0);
|
||||
floatl c = floatl(-3.14);
|
||||
floatl d = floatl(1.23456789e+10);
|
||||
floatl e = floatl(0x1.23456789p+10);
|
||||
|
||||
floatl f = floatl_from("0.0");
|
||||
floatl g = floatl_from("10.0");
|
||||
floatl h = floatl_from("-3.14");
|
||||
floatl i = floatl_from("1.23456789e+10");
|
||||
floatl j = floatl_from("0x1.23456789p+10");
|
||||
|
||||
floatl zero = FLOATL_CONST_0;
|
||||
floatl one = FLOATL_CONST_1;
|
||||
floatl ten = FLOATL_CONST_10;
|
||||
|
||||
printf("size %d\r\n", sizeof(floatl));
|
||||
}
|
||||
```
|
||||
|
||||
### 转换函数
|
||||
|
||||
```c
|
||||
int floatl_print(floatl a, char *buffer, uint32_t size, const char *format);
|
||||
#define floatl_show(a, b, s, f) (floatl_print((a), (b), (s), (f)) > 0 ? (b) : "invalid")
|
||||
```
|
||||
|
||||
此函数把`a`的值根据格式转换成十进制、`[P-]` 和 `[E-]`格式到传入的`buffer`中,并返回有效位的`buffer`地址。
|
||||
`buffer`和`size`分别是存储转换结果的缓冲区的地址和大小
|
||||
`format`使用与`printf`类似,```[flags][width][type]```,如`0.2f`、`+5.2a`等。
|
||||
|
||||
```c
|
||||
static void test_print(void)
|
||||
{
|
||||
floatl a = floatl_from("1234567890.123456789");
|
||||
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%f"));
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%.2f"));
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%020.2f"));
|
||||
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%+.6a"));
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%+20.6a"));
|
||||
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%-20.6e"));
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
```
|
||||
a 1234567890.123451
|
||||
a 1234567890.12
|
||||
a 00000001234567890.12
|
||||
a +0x1.26580bp+30
|
||||
a +0x1.26580bp+30
|
||||
a 1.234568e+009
|
||||
```
|
||||
|
||||
### 运算函数
|
||||
|
||||
```c
|
||||
floatl floatl_add(floatl a, floatl b); // a+b
|
||||
floatl floatl_sub(floatl a, floatl b); // a-b
|
||||
floatl floatl_mul(floatl a, floatl b); // a*b
|
||||
floatl floatl_div(floatl a, floatl b); // a/b
|
||||
floatl floatl_abs(floatl a); // |a|
|
||||
floatl floatl_neg(floatl a); // -a
|
||||
int floatl_eq(floatl a, floatl b); // a<b
|
||||
int floatl_ne(floatl a, floatl b); // a<=b
|
||||
int floatl_lt(floatl a, floatl b); // a==b
|
||||
int floatl_le(floatl a, floatl b); // a!=b
|
||||
int floatl_gt(floatl a, floatl b); // a>b
|
||||
int floatl_ge(floatl a, floatl b); // a>=b
|
||||
```
|
||||
|
||||
`floatl`运算函数与类似符号运算一致。
|
||||
|
||||
使用例子:
|
||||
```c
|
||||
static void test_calculate(void)
|
||||
{
|
||||
floatl a = floatl_from("123456789.123456789");
|
||||
floatl b = floatl_from("987654321.987654321");
|
||||
|
||||
printf("a %s\r\n", floatl_show(a, buffer, sizeof(buffer), "%f"));
|
||||
printf("b %s\r\n", floatl_show(b, buffer, sizeof(buffer), "%f"));
|
||||
|
||||
printf("a + b: %s\r\n", floatl_show(floatl_add(a, b), buffer, sizeof(buffer), "%f"));
|
||||
printf("a - b: %s\r\n", floatl_show(floatl_sub(a, b), buffer, sizeof(buffer), "%f"));
|
||||
printf("a * b: %s\r\n", floatl_show(floatl_mul(a, b), buffer, sizeof(buffer), "%f"));
|
||||
printf("b / a: %s\r\n", floatl_show(floatl_div(a, b), buffer, sizeof(buffer), "%f"));
|
||||
printf("-a: %s\r\n", floatl_show(floatl_neg(a), buffer, sizeof(buffer), "%f"));
|
||||
printf("|a|: %s\r\n", floatl_show(floatl_abs(a), buffer, sizeof(buffer), "%f"));
|
||||
printf("a > b: %d\r\n", floatl_gt(a, b));
|
||||
printf("a >= b: %d\r\n", floatl_ge(a, b));
|
||||
printf("a < b: %d\r\n", floatl_lt(a, b));
|
||||
printf("a <= b: %d\r\n", floatl_le(a, b));
|
||||
printf("a == b: %d\r\n", floatl_eq(a, b));
|
||||
printf("a != b: %d\r\n", floatl_ne(a, b));
|
||||
}
|
||||
```
|
||||
|
||||
结果:
|
||||
```
|
||||
a 123456789.123456
|
||||
b 987654321.987650
|
||||
a + b: 1111111111.111118
|
||||
a - b: -864197532.864200
|
||||
a * b: 121932631356500755.185485
|
||||
b / a: 0.125000
|
||||
-a: -123456789.123456
|
||||
|a|: 123456789.123456
|
||||
a > b: 0
|
||||
a >= b: 0
|
||||
a < b: 1
|
||||
a <= b: 1
|
||||
a == b: 0
|
||||
a != b: 1
|
||||
```
|
||||
|
||||
3
makefile
3
makefile
@ -20,6 +20,7 @@ CONTAINER_PATH = $(WORKSPACE)/03_container
|
||||
ALGORITHM_PATH = $(WORKSPACE)/04_algorithm
|
||||
PARSER_PATH = $(WORKSPACE)/05_parser
|
||||
PERFORMANCE_PATH = $(WORKSPACE)/06_performance
|
||||
MATH_PATH = $(WORKSPACE)/07_math
|
||||
|
||||
##################################################################################
|
||||
### sources, libaries and head path
|
||||
@ -31,6 +32,7 @@ INCLUDE += $(CONTAINER_PATH)
|
||||
INCLUDE += $(ALGORITHM_PATH)
|
||||
INCLUDE += $(PARSER_PATH)
|
||||
INCLUDE += $(PERFORMANCE_PATH)
|
||||
INCLUDE += $(MATH_PATH)
|
||||
|
||||
LIBSRCS += $(APPLICATION_PATH)/init.c
|
||||
LIBSRCS += $(wildcard $(APPLICATION_PATH)/console/*.c)
|
||||
@ -40,6 +42,7 @@ LIBSRCS += $(wildcard $(CONTAINER_PATH)/*.c)
|
||||
LIBSRCS += $(wildcard $(ALGORITHM_PATH)/*.c)
|
||||
LIBSRCS += $(wildcard $(PARSER_PATH)/*.c)
|
||||
LIBSRCS += $(wildcard $(PERFORMANCE_PATH)/*.c)
|
||||
LIBSRCS += $(wildcard $(MATH_PATH)/*.c)
|
||||
|
||||
LIBLIST += m
|
||||
LIBLIST += pthread
|
||||
|
||||
12
release.txt
12
release.txt
@ -1,3 +1,15 @@
|
||||
version 0.3.1
|
||||
date 2025.03.04
|
||||
changes
|
||||
1. Add math category folder
|
||||
2. Add the floatl initial version
|
||||
3. Add the intl_print function
|
||||
4. Fix intl_from issue
|
||||
5. Add intl unit test code
|
||||
|
||||
---------------------------------------------------------------------------------------------
|
||||
---------------------------------------------------------------------------------------------
|
||||
|
||||
version 0.3.0
|
||||
date 2024.12.18
|
||||
changes
|
||||
|
||||
@ -1,82 +0,0 @@
|
||||
|
||||
/*********************************************************************************************************
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* file description
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* \file intl.h
|
||||
* \unit intl
|
||||
* \brief This is a simple large inter number calculate module for C language
|
||||
* \author Lamdonn
|
||||
* \version v1.0.0
|
||||
* \license GPL-2.0
|
||||
* \copyright Copyright (C) 2023 Lamdonn.
|
||||
********************************************************************************************************/
|
||||
#ifndef __intl_H
|
||||
#define __intl_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "intl_cfg.h"
|
||||
|
||||
/* Version infomation */
|
||||
|
||||
#define INTL_V_MAJOR 1
|
||||
#define INTL_V_MINOR 0
|
||||
#define INTL_V_PATCH 0
|
||||
|
||||
/**
|
||||
* \brief A structure to represent a long bits integer.
|
||||
*
|
||||
* This structure uses a union to store the long bits integer in two different ways:
|
||||
* - An array of `INTL_U16_PARTS` uint16_t values, allowing for operations on individual 16-bit segments.
|
||||
* - An array of `INTL_U32_PARTS` uint32_t values, providing a way to work with 32-bit segments.
|
||||
*
|
||||
* The union allows for flexibility in how the data is accessed and manipulated,
|
||||
* depending on the needs of the operations being performed.
|
||||
*/
|
||||
typedef struct {
|
||||
union {
|
||||
uint16_t u16[INTL_U16_PARTS]; ///< Array of uint16_t values representing the long bit integer in 16-bit segments.
|
||||
uint32_t u32[INTL_U32_PARTS]; ///< Array of uint32_t values representing the long bit integer in 32-bit segments.
|
||||
};
|
||||
} intl;
|
||||
|
||||
/**
|
||||
* \brief intl large integer api declaration, support for basic addition, subtraction, multiplication, division, etc.
|
||||
*/
|
||||
|
||||
intl intl_add(intl a, intl b);
|
||||
intl intl_sub(intl a, intl b);
|
||||
intl intl_mul(intl a, intl b);
|
||||
intl intl_div(intl a, intl b);
|
||||
intl intl_mod(intl a, intl b);
|
||||
intl intl_and(intl a, intl b);
|
||||
intl intl_xor(intl a, intl b);
|
||||
intl intl_or(intl a, intl b);
|
||||
intl intl_shl(intl a, uint32_t amount);
|
||||
intl intl_shr(intl a, uint32_t amount);
|
||||
intl intl_not(intl a);
|
||||
intl intl_abs(intl a);
|
||||
intl intl_inc(intl a);
|
||||
intl intl_dec(intl a);
|
||||
intl intl_neg(intl a);
|
||||
intl intl_from(const char *str);
|
||||
intl intl_from2(int value);
|
||||
const char* intl_sdec(intl a, char buffer[INTL_MAX_DEC]);
|
||||
const char* intl_shex(intl a, char buffer[INTL_MAX_HEX]);
|
||||
const char* intl_sbin(intl a, char buffer[INTL_MAX_BIN]);
|
||||
int intl_cmp(intl a, intl b);
|
||||
int intl_sign(intl a);
|
||||
|
||||
/**
|
||||
* \brief Converts a integer to an intl number.
|
||||
* \param[in] value: The integer to convert.
|
||||
* \return The corresponding intl number initialized with the given value.
|
||||
*/
|
||||
#define intl(value) intl_from2(value)
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,224 +0,0 @@
|
||||
|
||||
/*********************************************************************************************************
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* file description
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* \file intl_cfg.h
|
||||
* \unit intl
|
||||
* \brief This is a simple large int number calculate module config header file for C language
|
||||
* \author Lamdonn
|
||||
* \version v1.0.0
|
||||
* \license GPL-2.0
|
||||
* \copyright Copyright (C) 2023 Lamdonn.
|
||||
********************************************************************************************************/
|
||||
#ifndef __intl_cfg_H
|
||||
#define __intl_cfg_H
|
||||
|
||||
/*
|
||||
* With this definition, you can configure the footprint size of an intl.
|
||||
* This is a flexible definition that can be extended to larger numbers in addition to the given few size definitions
|
||||
*/
|
||||
|
||||
/*****************************************************************/
|
||||
/* Config start */
|
||||
/*****************************************************************/
|
||||
// #define INTL_USE_128BITS
|
||||
// #define INTL_USE_256BITS
|
||||
#define INTL_USE_512BITS
|
||||
// #define INTL_USE_1024BITS
|
||||
// #define INTL_USE_2048BITS
|
||||
// #define INTL_USE_4096BITS
|
||||
// #define INTL_USE_8192BITS
|
||||
|
||||
#if defined(INTL_USE_128BITS)
|
||||
#define INTL_BIT_PARTS 128
|
||||
#define INTL_U32_PARTS 4
|
||||
#define INTL_U16_PARTS 8
|
||||
#define INTL_MAX_BIN 129
|
||||
#define INTL_MAX_DEC 40
|
||||
#define INTL_MAX_HEX 33
|
||||
#define INTL_MAX (intl){.u32={-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define INTL_MIN (intl){.u32={0,0,0,0x80000000,}}
|
||||
#define INTL_ZERO (intl){.u32={0,0,0,0,}}
|
||||
#elif defined(INTL_USE_256BITS)
|
||||
#define INTL_BIT_PARTS 256
|
||||
#define INTL_U32_PARTS 8
|
||||
#define INTL_U16_PARTS 16
|
||||
#define INTL_MAX_BIN 257
|
||||
#define INTL_MAX_DEC 78
|
||||
#define INTL_MAX_HEX 65
|
||||
#define INTL_MAX (intl){.u32={-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define INTL_MIN (intl){.u32={0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define INTL_ZERO (intl){.u32={0,0,0,0,0,0,0,0,}}
|
||||
#elif defined(INTL_USE_512BITS)
|
||||
#define INTL_BIT_PARTS 512
|
||||
#define INTL_U32_PARTS 16
|
||||
#define INTL_U16_PARTS 32
|
||||
#define INTL_MAX_BIN 513
|
||||
#define INTL_MAX_DEC 155
|
||||
#define INTL_MAX_HEX 129
|
||||
#define INTL_MAX (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define INTL_MIN (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define INTL_ZERO (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#elif defined(INTL_USE_1024BITS)
|
||||
#define INTL_BIT_PARTS 1024
|
||||
#define INTL_U32_PARTS 32
|
||||
#define INTL_U16_PARTS 64
|
||||
#define INTL_MAX_BIN 1025
|
||||
#define INTL_MAX_DEC 309
|
||||
#define INTL_MAX_HEX 257
|
||||
#define INTL_MAX (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define INTL_MIN (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define INTL_ZERO (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#elif defined(INTL_USE_2048BITS)
|
||||
#define INTL_BIT_PARTS 2048
|
||||
#define INTL_U32_PARTS 64
|
||||
#define INTL_U16_PARTS 128
|
||||
#define INTL_MAX_BIN 2049
|
||||
#define INTL_MAX_DEC 618
|
||||
#define INTL_MAX_HEX 513
|
||||
#define INTL_MAX (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define INTL_MIN (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define INTL_ZERO (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#elif defined(INTL_USE_4096BITS)
|
||||
#define INTL_BIT_PARTS 4096
|
||||
#define INTL_U32_PARTS 128
|
||||
#define INTL_U16_PARTS 256
|
||||
#define INTL_MAX_BIN 4097
|
||||
#define INTL_MAX_DEC 1234
|
||||
#define INTL_MAX_HEX 1025
|
||||
#define INTL_MAX (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define INTL_MIN (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define INTL_ZERO (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#elif defined(INTL_USE_8192BITS)
|
||||
#define INTL_BIT_PARTS 8192
|
||||
#define INTL_U32_PARTS 256
|
||||
#define INTL_U16_PARTS 512
|
||||
#define INTL_MAX_BIN 8193
|
||||
#define INTL_MAX_DEC 2468
|
||||
#define INTL_MAX_HEX 2049
|
||||
#define INTL_MAX (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define INTL_ZERO (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#endif
|
||||
/*****************************************************************/
|
||||
/* Config end */
|
||||
/*****************************************************************/
|
||||
|
||||
#if 0
|
||||
void intl_gen_cfg(uint32_t bits)
|
||||
{
|
||||
if ((bits & (bits - 1)) != 0)
|
||||
{
|
||||
printf("[ERROR] `bits` not a power of 2\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (bits < 128)
|
||||
{
|
||||
printf("[ERROR] `bits` too small\r\b");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("/*****************************************************************/\r\n");
|
||||
printf("/* Config start */\r\n");
|
||||
printf("/*****************************************************************/\r\n");
|
||||
|
||||
for (uint32_t tb = 128; tb <= bits; tb <<= 1)
|
||||
{
|
||||
if (tb == bits)
|
||||
{
|
||||
printf("#define INTL_USE_%uBITS\r\n", tb);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("// #define INTL_USE_%uBITS\r\n", tb);
|
||||
}
|
||||
}
|
||||
printf("\r\n");
|
||||
|
||||
intl temp;
|
||||
|
||||
for (uint32_t tb = 128; tb <= bits; tb <<= 1)
|
||||
{
|
||||
if (tb == 128)
|
||||
{
|
||||
printf("#if defined(INTL_USE_%uBITS)\r\n", tb);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
printf("#elif defined(INTL_USE_%uBITS)\r\n", tb);
|
||||
}
|
||||
|
||||
uint32_t BIT_PARTS ; /* bits */
|
||||
uint32_t U32_PARTS ; /* INTL_BIT_PARTS / 32 */
|
||||
uint32_t U16_PARTS ; /* INTL_BIT_PARTS / 16 */
|
||||
uint32_t MAX_BIN ; /* INTL_BIT_PARTS + 1 */
|
||||
uint32_t MAX_DEC ; /* strlen(intl_shl(intl(1), INTL_BIT_PARTS - 1)) + 1 */
|
||||
uint32_t MAX_HEX ; /* INTL_BIT_PARTS / 4 + 1 */
|
||||
|
||||
BIT_PARTS = tb;
|
||||
U32_PARTS = BIT_PARTS >> (5);
|
||||
U16_PARTS = BIT_PARTS >> (4);
|
||||
MAX_BIN = BIT_PARTS + 1;
|
||||
MAX_DEC = MAX_BIN;
|
||||
MAX_HEX = (BIT_PARTS >> (2)) + 1;
|
||||
|
||||
if (sizeof(temp) == (bits >> 3))
|
||||
{
|
||||
char buffer[INTL_MAX_BIN];
|
||||
MAX_DEC = strlen(intl_sdec(intl_shl(intl(1), BIT_PARTS - 1), buffer)) + 1;
|
||||
}
|
||||
|
||||
printf("#define INTL_BIT_PARTS %u\r\n", BIT_PARTS);
|
||||
printf("#define INTL_U32_PARTS %u\r\n", U32_PARTS);
|
||||
printf("#define INTL_U16_PARTS %u\r\n", U16_PARTS);
|
||||
printf("#define INTL_MAX_BIN %u\r\n", MAX_BIN);
|
||||
printf("#define INTL_MAX_DEC %u\r\n", MAX_DEC);
|
||||
printf("#define INTL_MAX_HEX %u\r\n", MAX_HEX);
|
||||
intl max = (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}};
|
||||
intl min = (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}};
|
||||
printf("#define INTL_MAX (intl){.u32={");
|
||||
for (uint32_t i = 0; i < U32_PARTS; i++)
|
||||
{
|
||||
printf("%s,", (i == U32_PARTS-1) ? "0x7FFFFFFF" : "-1");
|
||||
}
|
||||
printf("}}\r\n");
|
||||
|
||||
printf("#define INTL_MIN (intl){.u32={");
|
||||
for (uint32_t i = 0; i < U32_PARTS; i++)
|
||||
{
|
||||
printf("%s,", (i == U32_PARTS-1) ? "0x80000000" : "0");
|
||||
}
|
||||
printf("}}\r\n");
|
||||
|
||||
printf("#define INTL_ZERO (intl){.u32={");
|
||||
for (uint32_t i = 0; i < U32_PARTS; i++)
|
||||
{
|
||||
printf("0,");
|
||||
}
|
||||
printf("}}\r\n");
|
||||
}
|
||||
|
||||
printf("#endif\r\n");
|
||||
|
||||
printf("/*****************************************************************/\r\n");
|
||||
printf("/* Config end */\r\n");
|
||||
printf("/*****************************************************************/\r\n");
|
||||
|
||||
printf("\r\n\r\n-------------------------------------------------------------\r\n\r\n");
|
||||
|
||||
if (sizeof(temp) != (bits >> 3))
|
||||
{
|
||||
printf("[TODO] Apply the current configuration and run it again to get the new `INTL_MAX_DEC`\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("[INFO] The configuration has been generated, copy it to the `intl_cfg.h` range specified\r\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
3783
source/07_math/floatl.c
Normal file
3783
source/07_math/floatl.c
Normal file
File diff suppressed because it is too large
Load Diff
174
source/07_math/floatl.h
Normal file
174
source/07_math/floatl.h
Normal file
@ -0,0 +1,174 @@
|
||||
|
||||
/*********************************************************************************************************
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* file description
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* \file floatl.h
|
||||
* \unit floatl
|
||||
* \brief This is a simple large float number calculate module for C language
|
||||
* \author Lamdonn
|
||||
* \version v1.0.0
|
||||
* \license GPL-2.0
|
||||
* \copyright Copyright (C) 2023 Lamdonn.
|
||||
********************************************************************************************************/
|
||||
#ifndef __floatl_H
|
||||
#define __floatl_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "floatl_cfg.h"
|
||||
|
||||
/* Version infomation */
|
||||
|
||||
#define FLOATL_V_MAJOR 1
|
||||
#define FLOATL_V_MINOR 0
|
||||
#define FLOATL_V_PATCH 0
|
||||
|
||||
/**
|
||||
* \brief Common constant definitions
|
||||
*/
|
||||
|
||||
#define FLOATL_INF __FLOATL_INF__
|
||||
#define FLOATL_NAN __FLOATL_NAN__
|
||||
#define FLOATL_CONST_0 __FLOATL_CONST_0__
|
||||
#define FLOATL_CONST_1 __FLOATL_CONST_1__
|
||||
#define FLOATL_CONST_10 __FLOATL_CONST_1e1__
|
||||
#define FLOATL_CONST_100 __FLOATL_CONST_1e2__
|
||||
#define FLOATL_CONST_1000 __FLOATL_CONST_1e3__
|
||||
#define FLOATL_CONST_1e0 __FLOATL_CONST_1e0__
|
||||
#define FLOATL_CONST_1e1 __FLOATL_CONST_1e1__
|
||||
#define FLOATL_CONST_1e2 __FLOATL_CONST_1e2__
|
||||
#define FLOATL_CONST_1e3 __FLOATL_CONST_1e3__
|
||||
#define FLOATL_CONST_1e4 __FLOATL_CONST_1e4__
|
||||
#define FLOATL_CONST_1e5 __FLOATL_CONST_1e5__
|
||||
#define FLOATL_CONST_1e6 __FLOATL_CONST_1e6__
|
||||
#define FLOATL_CONST_1e7 __FLOATL_CONST_1e7__
|
||||
#define FLOATL_CONST_1e8 __FLOATL_CONST_1e8__
|
||||
#define FLOATL_CONST_1e9 __FLOATL_CONST_1e9__
|
||||
#define FLOATL_CONST_1e10 __FLOATL_CONST_1e10__
|
||||
#define FLOATL_CONST_1e11 __FLOATL_CONST_1e11__
|
||||
#define FLOATL_CONST_1e12 __FLOATL_CONST_1e12__
|
||||
#define FLOATL_CONST_1e13 __FLOATL_CONST_1e13__
|
||||
#define FLOATL_CONST_1e14 __FLOATL_CONST_1e14__
|
||||
#define FLOATL_CONST_1e15 __FLOATL_CONST_1e15__
|
||||
|
||||
/**
|
||||
* \brief A structure to represent a long bits integer.
|
||||
*
|
||||
* This structure uses a union to store the long bits integer in two different ways:
|
||||
* - An array of `__FLOATL_U16_PARTS__` uint16_t values, allowing for operations on individual 16-bit segments.
|
||||
* - An array of `__FLOATL_U32_PARTS__` uint32_t values, providing a way to work with 32-bit segments.
|
||||
*
|
||||
* The union allows for flexibility in how the data is accessed and manipulated,
|
||||
* depending on the needs of the operations being performed.
|
||||
*/
|
||||
typedef struct {
|
||||
union {
|
||||
uint16_t u16[__FLOATL_U16_PARTS__]; ///< Array of uint16_t values representing the long bit integer in 16-bit segments.
|
||||
uint32_t u32[__FLOATL_U32_PARTS__]; ///< Array of uint32_t values representing the long bit integer in 32-bit segments.
|
||||
struct {
|
||||
uint32_t mantissas[__FLOATL_MANT_PARTS__];
|
||||
uint32_t mantissa : __FLOATL_MANT_HIGH_BITS__;
|
||||
uint32_t exponent : __FLOATL_EXP_BITS__;
|
||||
uint32_t sign : 1;
|
||||
};
|
||||
};
|
||||
} floatl;
|
||||
|
||||
/**
|
||||
* \brief floatl large integer api declaration, support for basic addition, subtraction, multiplication, division, etc.
|
||||
*/
|
||||
|
||||
// Comparison functions
|
||||
// floatl_eq: Checks if two floatl numbers are equal
|
||||
// floatl_ne: Checks if two floatl numbers are not equal
|
||||
// floatl_lt: Checks if the first floatl number is less than the second
|
||||
// floatl_le: Checks if the first floatl number is less than or equal to the second
|
||||
// floatl_gt: Checks if the first floatl number is greater than the second
|
||||
// floatl_ge: Checks if the first floatl number is greater than or equal to the second
|
||||
|
||||
int floatl_eq(floatl a, floatl b);
|
||||
int floatl_ne(floatl a, floatl b);
|
||||
int floatl_lt(floatl a, floatl b);
|
||||
int floatl_le(floatl a, floatl b);
|
||||
int floatl_gt(floatl a, floatl b);
|
||||
int floatl_ge(floatl a, floatl b);
|
||||
|
||||
// Arithmetic operation functions
|
||||
// floatl_add: Performs addition of two floatl numbers, equivalent to the '+' operator
|
||||
// floatl_sub: Performs subtraction of two floatl numbers, equivalent to the '-' operator
|
||||
// floatl_mul: Performs multiplication of two floatl numbers, equivalent to the '*' operator
|
||||
// floatl_div: Performs division of two floatl numbers, equivalent to the '/' operator
|
||||
|
||||
floatl floatl_add(floatl a, floatl b);
|
||||
floatl floatl_sub(floatl a, floatl b);
|
||||
floatl floatl_mul(floatl a, floatl b);
|
||||
floatl floatl_div(floatl a, floatl b);
|
||||
|
||||
// Attribute checking functions
|
||||
// floatl_sign: Determines the sign of a floatl number (returns 1 for positive, -1 for negative, 0 for zero)
|
||||
// floatl_isnan: Checks if a floatl number is NaN (Not a Number)
|
||||
// floatl_isinf: Checks if a floatl number is infinite
|
||||
// floatl_isnormal: Checks if a floatl number is a normal number (not zero, NaN, or infinite)
|
||||
|
||||
int floatl_sign(floatl a);
|
||||
int floatl_isnan(floatl a);
|
||||
int floatl_isinf(floatl a);
|
||||
int floatl_isnormal(floatl a);
|
||||
|
||||
// Value modification functions
|
||||
// floatl_abs: Computes the absolute value of a floatl number
|
||||
// floatl_neg: Computes the negation of a floatl number, equivalent to the unary '-' operator
|
||||
|
||||
floatl floatl_abs(floatl a);
|
||||
floatl floatl_neg(floatl a);
|
||||
|
||||
// Conversion functions
|
||||
// floatl_from: Converts a string to a floatl number
|
||||
// floatl_from_f: Converts a single-precision floating-point number (float) to a floatl number
|
||||
// floatl_from_d: Converts a double-precision floating-point number (double) to a floatl number
|
||||
|
||||
floatl floatl_from(const char *str);
|
||||
floatl floatl_from_f(float value);
|
||||
floatl floatl_from_d(double value);
|
||||
|
||||
// Output function
|
||||
// Converts a floatl number to a string according to the specified format and stores it in the buffer
|
||||
|
||||
int floatl_print(floatl a, char *buffer, uint32_t size, const char *format);
|
||||
|
||||
/**
|
||||
* \brief Converts an integer to a 'floatl' number.
|
||||
*
|
||||
* This macro provides a convenient way to convert an integer value to a 'floatl' type number.
|
||||
* It simply calls the 'floatl_from_d' function, which is assumed to be defined elsewhere,
|
||||
* to perform the actual conversion.
|
||||
*
|
||||
* \param[in] value: The integer value to be converted to a 'floatl' number.
|
||||
* \return The corresponding 'floatl' number initialized with the given integer value.
|
||||
*/
|
||||
#define floatl(value) floatl_from_d(value)
|
||||
|
||||
/**
|
||||
* \brief A macro to convert a 'floatl' number to a string and handle potential conversion errors.
|
||||
*
|
||||
* This macro uses the 'floatl_print' function to convert a 'floatl' number 'a' to a string and
|
||||
* store it in the buffer 'b' with a given buffer size 's' according to the format string 'f'.
|
||||
* If the conversion is successful (i.e., 'floatl_print' returns a value greater than 0), it returns
|
||||
* the pointer to the buffer 'b' containing the converted string. Otherwise, it returns the string
|
||||
* "invalid" to indicate that the conversion was not successful.
|
||||
*
|
||||
* \param a: The 'floatl' number to be converted.
|
||||
* \param b: A pointer to the buffer where the converted string will be stored.
|
||||
* \param s: The size of the buffer 'b'.
|
||||
* \param f: A printf-like format string specifying how the 'floatl' number should be formatted.
|
||||
* \return A pointer to the buffer 'b' if the conversion is successful; otherwise, a pointer to the
|
||||
* string literal "invalid".
|
||||
*/
|
||||
#define floatl_show(a, b, s, f) (floatl_print((a), (b), (s), (f)) > 0 ? (b) : "invalid")
|
||||
|
||||
#endif
|
||||
|
||||
779
source/07_math/floatl_cfg.h
Normal file
779
source/07_math/floatl_cfg.h
Normal file
@ -0,0 +1,779 @@
|
||||
|
||||
/*********************************************************************************************************
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* file description
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* \file floatl_cfg.h
|
||||
* \unit floatl
|
||||
* \brief This is a simple large int number calculate module config header file for C language
|
||||
* \author Lamdonn
|
||||
* \version v1.0.0
|
||||
* \license GPL-2.0
|
||||
* \copyright Copyright (C) 2023 Lamdonn.
|
||||
********************************************************************************************************/
|
||||
#ifndef __floatl_cfg_H
|
||||
#define __floatl_cfg_H
|
||||
|
||||
/*
|
||||
* With this definition, you can configure the footprint size of an floatl.
|
||||
* This is a flexible definition that can be extended to larger numbers in addition to the given few size definitions
|
||||
*/
|
||||
|
||||
/*****************************************************************/
|
||||
/* Config start */
|
||||
/*****************************************************************/
|
||||
// #define FLOATL_USE_64BITS
|
||||
// #define FLOATL_USE_128BITS
|
||||
// #define FLOATL_USE_256BITS
|
||||
#define FLOATL_USE_512BITS
|
||||
// #define FLOATL_USE_1024BITS
|
||||
// #define FLOATL_USE_2048BITS
|
||||
// #define FLOATL_USE_4096BITS
|
||||
// #define FLOATL_USE_8192BITS
|
||||
|
||||
#if defined(FLOATL_USE_64BITS)
|
||||
#define __FLOATL_BIT_PARTS__ 64
|
||||
#define __FLOATL_U32_PARTS__ 2
|
||||
#define __FLOATL_U16_PARTS__ 4
|
||||
#define __FLOATL_EXP_BITS__ 11
|
||||
#define __FLOATL_MANT_BITS__ 52
|
||||
#define __FLOATL_MANT_PARTS__ 1
|
||||
#define __FLOATL_MANT_HIGH_BITS__ 20
|
||||
#define __FLOATL_EXP_MID_VALUE__ 1023
|
||||
#define __FLOATL_EXP_WHL_VALUE__ 2047
|
||||
#define __FLOATL2_BIT_PARTS__ 128
|
||||
#define __FLOATL2_U32_PARTS__ 4
|
||||
#define __FLOATL2_U16_PARTS__ 8
|
||||
#define __FLOATL_CONST_0__ (floatl){.u32={0,0,}}
|
||||
#define __FLOATL_CONST_1__ (floatl){.u32={0,0x3FF00000,}}
|
||||
#define __FLOATL_CONST_1e0__ (floatl){.u32={0,0x3FF00000,}}
|
||||
#define __FLOATL_CONST_1e1__ (floatl){.u32={0,0x40240000,}}
|
||||
#define __FLOATL_CONST_1e2__ (floatl){.u32={0,0x40590000,}}
|
||||
#define __FLOATL_CONST_1e3__ (floatl){.u32={0,0x408F4000,}}
|
||||
#define __FLOATL_CONST_1e4__ (floatl){.u32={0,0x40C38800,}}
|
||||
#define __FLOATL_CONST_1e5__ (floatl){.u32={0,0x40F86A00,}}
|
||||
#define __FLOATL_CONST_1e6__ (floatl){.u32={0,0x412E8480,}}
|
||||
#define __FLOATL_CONST_1e7__ (floatl){.u32={0,0x416312D0,}}
|
||||
#define __FLOATL_CONST_1e8__ (floatl){.u32={0,0x4197D784,}}
|
||||
#define __FLOATL_CONST_1e9__ (floatl){.u32={0,0x41CDCD65,}}
|
||||
#define __FLOATL_CONST_1e10__ (floatl){.u32={0x20000000,0x4202A05F,}}
|
||||
#define __FLOATL_CONST_1e11__ (floatl){.u32={0xE8000000,0x42374876,}}
|
||||
#define __FLOATL_CONST_1e12__ (floatl){.u32={0xA2000000,0x426D1A94,}}
|
||||
#define __FLOATL_CONST_1e13__ (floatl){.u32={0xE5400000,0x42A2309C,}}
|
||||
#define __FLOATL_CONST_1e14__ (floatl){.u32={0x1E900000,0x42D6BCC4,}}
|
||||
#define __FLOATL_CONST_1e15__ (floatl){.u32={0x26340000,0x430C6BF5,}}
|
||||
#define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,}}
|
||||
#define __FLOATL_INF__ (floatl){.u32={0,0x7FF00000,}}
|
||||
#define __FLOATL_NAN__ (floatl){.u32={0,0xFFF00000,}}
|
||||
#define __FLOATL_ALL_SIGN__ (floatl){.u32={0,0x80000000,}}
|
||||
#define __FLOATL_ALL_EXP__ (floatl){.u32={0,0x7FF00000,}}
|
||||
#define __FLOATL_ALL_MANT__ (floatl){.u32={-1,0x000FFFFF,}}
|
||||
#define __FLOATL_ALL_EXP_MANT__ (floatl){.u32={-1,0x7FFFFFFF,}}
|
||||
#define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0x00100000,}}
|
||||
#define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0x00800000,}}
|
||||
#define __FLOATL_MANT_WHL__ (floatl){.u32={-1,0x001FFFFF,}}
|
||||
#elif defined(FLOATL_USE_128BITS)
|
||||
#define __FLOATL_BIT_PARTS__ 128
|
||||
#define __FLOATL_U32_PARTS__ 4
|
||||
#define __FLOATL_U16_PARTS__ 8
|
||||
#define __FLOATL_EXP_BITS__ 13
|
||||
#define __FLOATL_MANT_BITS__ 114
|
||||
#define __FLOATL_MANT_PARTS__ 3
|
||||
#define __FLOATL_MANT_HIGH_BITS__ 18
|
||||
#define __FLOATL_EXP_MID_VALUE__ 4095
|
||||
#define __FLOATL_EXP_WHL_VALUE__ 8191
|
||||
#define __FLOATL2_BIT_PARTS__ 256
|
||||
#define __FLOATL2_U32_PARTS__ 8
|
||||
#define __FLOATL2_U16_PARTS__ 16
|
||||
#define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,}}
|
||||
#define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0x3FFC0000,}}
|
||||
#define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0x3FFC0000,}}
|
||||
#define __FLOATL_CONST_1e1__ (floatl){.u32={0,0,0,0x40090000,}}
|
||||
#define __FLOATL_CONST_1e2__ (floatl){.u32={0,0,0,0x40164000,}}
|
||||
#define __FLOATL_CONST_1e3__ (floatl){.u32={0,0,0,0x4023D000,}}
|
||||
#define __FLOATL_CONST_1e4__ (floatl){.u32={0,0,0,0x4030E200,}}
|
||||
#define __FLOATL_CONST_1e5__ (floatl){.u32={0,0,0,0x403E1A80,}}
|
||||
#define __FLOATL_CONST_1e6__ (floatl){.u32={0,0,0,0x404BA120,}}
|
||||
#define __FLOATL_CONST_1e7__ (floatl){.u32={0,0,0,0x4058C4B4,}}
|
||||
#define __FLOATL_CONST_1e8__ (floatl){.u32={0,0,0,0x4065F5E1,}}
|
||||
#define __FLOATL_CONST_1e9__ (floatl){.u32={0,0,0x40000000,0x40737359,}}
|
||||
#define __FLOATL_CONST_1e10__ (floatl){.u32={0,0,0xC8000000,0x4080A817,}}
|
||||
#define __FLOATL_CONST_1e11__ (floatl){.u32={0,0,0xBA000000,0x408DD21D,}}
|
||||
#define __FLOATL_CONST_1e12__ (floatl){.u32={0,0,0x28800000,0x409B46A5,}}
|
||||
#define __FLOATL_CONST_1e13__ (floatl){.u32={0,0,0x39500000,0x40A88C27,}}
|
||||
#define __FLOATL_CONST_1e14__ (floatl){.u32={0,0,0x07A40000,0x40B5AF31,}}
|
||||
#define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0x498D0000,0x40C31AFD,}}
|
||||
#define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,}}
|
||||
#define __FLOATL_INF__ (floatl){.u32={0,0,0,0x7FFC0000,}}
|
||||
#define __FLOATL_NAN__ (floatl){.u32={0,0,0,0xFFFC0000,}}
|
||||
#define __FLOATL_ALL_SIGN__ (floatl){.u32={0,0,0,0x80000000,}}
|
||||
#define __FLOATL_ALL_EXP__ (floatl){.u32={0,0,0,0x7FFC0000,}}
|
||||
#define __FLOATL_ALL_MANT__ (floatl){.u32={-1,-1,-1,0x0003FFFF,}}
|
||||
#define __FLOATL_ALL_EXP_MANT__ (floatl){.u32={-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0,0,0x00040000,}}
|
||||
#define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0,0,0x00200000,}}
|
||||
#define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,0x0007FFFF,}}
|
||||
#elif defined(FLOATL_USE_256BITS)
|
||||
#define __FLOATL_BIT_PARTS__ 256
|
||||
#define __FLOATL_U32_PARTS__ 8
|
||||
#define __FLOATL_U16_PARTS__ 16
|
||||
#define __FLOATL_EXP_BITS__ 15
|
||||
#define __FLOATL_MANT_BITS__ 240
|
||||
#define __FLOATL_MANT_PARTS__ 7
|
||||
#define __FLOATL_MANT_HIGH_BITS__ 16
|
||||
#define __FLOATL_EXP_MID_VALUE__ 16383
|
||||
#define __FLOATL_EXP_WHL_VALUE__ 32767
|
||||
#define __FLOATL2_BIT_PARTS__ 512
|
||||
#define __FLOATL2_U32_PARTS__ 16
|
||||
#define __FLOATL2_U16_PARTS__ 32
|
||||
#define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,}}
|
||||
#define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0,0,0,0,0x3FFF0000,}}
|
||||
#define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0,0,0,0,0x3FFF0000,}}
|
||||
#define __FLOATL_CONST_1e1__ (floatl){.u32={0,0,0,0,0,0,0,0x40024000,}}
|
||||
#define __FLOATL_CONST_1e2__ (floatl){.u32={0,0,0,0,0,0,0,0x40059000,}}
|
||||
#define __FLOATL_CONST_1e3__ (floatl){.u32={0,0,0,0,0,0,0,0x4008F400,}}
|
||||
#define __FLOATL_CONST_1e4__ (floatl){.u32={0,0,0,0,0,0,0,0x400C3880,}}
|
||||
#define __FLOATL_CONST_1e5__ (floatl){.u32={0,0,0,0,0,0,0,0x400F86A0,}}
|
||||
#define __FLOATL_CONST_1e6__ (floatl){.u32={0,0,0,0,0,0,0,0x4012E848,}}
|
||||
#define __FLOATL_CONST_1e7__ (floatl){.u32={0,0,0,0,0,0,0,0x4016312D,}}
|
||||
#define __FLOATL_CONST_1e8__ (floatl){.u32={0,0,0,0,0,0,0x40000000,0x40197D78,}}
|
||||
#define __FLOATL_CONST_1e9__ (floatl){.u32={0,0,0,0,0,0,0x50000000,0x401CDCD6,}}
|
||||
#define __FLOATL_CONST_1e10__ (floatl){.u32={0,0,0,0,0,0,0xF2000000,0x40202A05,}}
|
||||
#define __FLOATL_CONST_1e11__ (floatl){.u32={0,0,0,0,0,0,0x6E800000,0x40237487,}}
|
||||
#define __FLOATL_CONST_1e12__ (floatl){.u32={0,0,0,0,0,0,0x4A200000,0x4026D1A9,}}
|
||||
#define __FLOATL_CONST_1e13__ (floatl){.u32={0,0,0,0,0,0,0xCE540000,0x402A2309,}}
|
||||
#define __FLOATL_CONST_1e14__ (floatl){.u32={0,0,0,0,0,0,0x41E90000,0x402D6BCC,}}
|
||||
#define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0,0,0,0,0x52634000,0x4030C6BF,}}
|
||||
#define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,0,0,0,0,}}
|
||||
#define __FLOATL_INF__ (floatl){.u32={0,0,0,0,0,0,0,0x7FFF0000,}}
|
||||
#define __FLOATL_NAN__ (floatl){.u32={0,0,0,0,0,0,0,0xFFFF0000,}}
|
||||
#define __FLOATL_ALL_SIGN__ (floatl){.u32={0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define __FLOATL_ALL_EXP__ (floatl){.u32={0,0,0,0,0,0,0,0x7FFF0000,}}
|
||||
#define __FLOATL_ALL_MANT__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,0x0000FFFF,}}
|
||||
#define __FLOATL_ALL_EXP_MANT__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0,0,0,0,0,0,0x00010000,}}
|
||||
#define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0,0,0,0,0,0,0x00080000,}}
|
||||
#define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,0x0001FFFF,}}
|
||||
#elif defined(FLOATL_USE_512BITS)
|
||||
#define __FLOATL_BIT_PARTS__ 512
|
||||
#define __FLOATL_U32_PARTS__ 16
|
||||
#define __FLOATL_U16_PARTS__ 32
|
||||
#define __FLOATL_EXP_BITS__ 17
|
||||
#define __FLOATL_MANT_BITS__ 494
|
||||
#define __FLOATL_MANT_PARTS__ 15
|
||||
#define __FLOATL_MANT_HIGH_BITS__ 14
|
||||
#define __FLOATL_EXP_MID_VALUE__ 65535
|
||||
#define __FLOATL_EXP_WHL_VALUE__ 131071
|
||||
#define __FLOATL2_BIT_PARTS__ 1024
|
||||
#define __FLOATL2_U32_PARTS__ 32
|
||||
#define __FLOATL2_U16_PARTS__ 64
|
||||
#define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFC000,}}
|
||||
#define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFC000,}}
|
||||
#define __FLOATL_CONST_1e1__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x40009000,}}
|
||||
#define __FLOATL_CONST_1e2__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x40016400,}}
|
||||
#define __FLOATL_CONST_1e3__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x40023D00,}}
|
||||
#define __FLOATL_CONST_1e4__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x40030E20,}}
|
||||
#define __FLOATL_CONST_1e5__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x4003E1A8,}}
|
||||
#define __FLOATL_CONST_1e6__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x4004BA12,}}
|
||||
#define __FLOATL_CONST_1e7__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x40000000,0x40058C4B,}}
|
||||
#define __FLOATL_CONST_1e8__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x10000000,0x40065F5E,}}
|
||||
#define __FLOATL_CONST_1e9__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x94000000,0x40073735,}}
|
||||
#define __FLOATL_CONST_1e10__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x7C800000,0x40080A81,}}
|
||||
#define __FLOATL_CONST_1e11__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xDBA00000,0x4008DD21,}}
|
||||
#define __FLOATL_CONST_1e12__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x52880000,0x4009B46A,}}
|
||||
#define __FLOATL_CONST_1e13__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x73950000,0x400A88C2,}}
|
||||
#define __FLOATL_CONST_1e14__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x107A4000,0x400B5AF3,}}
|
||||
#define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xD498D000,0x400C31AF,}}
|
||||
#define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#define __FLOATL_INF__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x7FFFC000,}}
|
||||
#define __FLOATL_NAN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFFFFC000,}}
|
||||
#define __FLOATL_ALL_SIGN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define __FLOATL_ALL_EXP__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x7FFFC000,}}
|
||||
#define __FLOATL_ALL_MANT__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x00003FFF,}}
|
||||
#define __FLOATL_ALL_EXP_MANT__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00004000,}}
|
||||
#define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00020000,}}
|
||||
#define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x00007FFF,}}
|
||||
#elif defined(FLOATL_USE_1024BITS)
|
||||
#define __FLOATL_BIT_PARTS__ 1024
|
||||
#define __FLOATL_U32_PARTS__ 32
|
||||
#define __FLOATL_U16_PARTS__ 64
|
||||
#define __FLOATL_EXP_BITS__ 19
|
||||
#define __FLOATL_MANT_BITS__ 1004
|
||||
#define __FLOATL_MANT_PARTS__ 31
|
||||
#define __FLOATL_MANT_HIGH_BITS__ 12
|
||||
#define __FLOATL_EXP_MID_VALUE__ 262143
|
||||
#define __FLOATL_EXP_WHL_VALUE__ 524287
|
||||
#define __FLOATL2_BIT_PARTS__ 2048
|
||||
#define __FLOATL2_U32_PARTS__ 64
|
||||
#define __FLOATL2_U16_PARTS__ 128
|
||||
#define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFF000,}}
|
||||
#define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFF000,}}
|
||||
#define __FLOATL_CONST_1e1__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x40002400,}}
|
||||
#define __FLOATL_CONST_1e2__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x40005900,}}
|
||||
#define __FLOATL_CONST_1e3__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x40008F40,}}
|
||||
#define __FLOATL_CONST_1e4__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x4000C388,}}
|
||||
#define __FLOATL_CONST_1e5__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x4000F86A,}}
|
||||
#define __FLOATL_CONST_1e6__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,0x40012E84,}}
|
||||
#define __FLOATL_CONST_1e7__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xD0000000,0x40016312,}}
|
||||
#define __FLOATL_CONST_1e8__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x84000000,0x400197D7,}}
|
||||
#define __FLOATL_CONST_1e9__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x65000000,0x4001CDCD,}}
|
||||
#define __FLOATL_CONST_1e10__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x5F200000,0x400202A0,}}
|
||||
#define __FLOATL_CONST_1e11__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x76E80000,0x40023748,}}
|
||||
#define __FLOATL_CONST_1e12__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x94A20000,0x40026D1A,}}
|
||||
#define __FLOATL_CONST_1e13__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x9CE54000,0x4002A230,}}
|
||||
#define __FLOATL_CONST_1e14__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xC41E9000,0x4002D6BC,}}
|
||||
#define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xF5263400,0x40030C6B,}}
|
||||
#define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#define __FLOATL_INF__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x7FFFF000,}}
|
||||
#define __FLOATL_NAN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFFFFF000,}}
|
||||
#define __FLOATL_ALL_SIGN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define __FLOATL_ALL_EXP__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x7FFFF000,}}
|
||||
#define __FLOATL_ALL_MANT__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x00000FFF,}}
|
||||
#define __FLOATL_ALL_EXP_MANT__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00001000,}}
|
||||
#define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00008000,}}
|
||||
#define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x00001FFF,}}
|
||||
#elif defined(FLOATL_USE_2048BITS)
|
||||
#define __FLOATL_BIT_PARTS__ 2048
|
||||
#define __FLOATL_U32_PARTS__ 64
|
||||
#define __FLOATL_U16_PARTS__ 128
|
||||
#define __FLOATL_EXP_BITS__ 21
|
||||
#define __FLOATL_MANT_BITS__ 2026
|
||||
#define __FLOATL_MANT_PARTS__ 63
|
||||
#define __FLOATL_MANT_HIGH_BITS__ 10
|
||||
#define __FLOATL_EXP_MID_VALUE__ 1048575
|
||||
#define __FLOATL_EXP_WHL_VALUE__ 2097151
|
||||
#define __FLOATL2_BIT_PARTS__ 4096
|
||||
#define __FLOATL2_U32_PARTS__ 128
|
||||
#define __FLOATL2_U16_PARTS__ 256
|
||||
#define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFFC00,}}
|
||||
#define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFFC00,}}
|
||||
#define __FLOATL_CONST_1e1__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x40000900,}}
|
||||
#define __FLOATL_CONST_1e2__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x40001640,}}
|
||||
#define __FLOATL_CONST_1e3__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x400023D0,}}
|
||||
#define __FLOATL_CONST_1e4__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x400030E2,}}
|
||||
#define __FLOATL_CONST_1e5__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,0x40003E1A,}}
|
||||
#define __FLOATL_CONST_1e6__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x20000000,0x40004BA1,}}
|
||||
#define __FLOATL_CONST_1e7__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xB4000000,0x400058C4,}}
|
||||
#define __FLOATL_CONST_1e8__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xE1000000,0x400065F5,}}
|
||||
#define __FLOATL_CONST_1e9__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x59400000,0x40007373,}}
|
||||
#define __FLOATL_CONST_1e10__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x17C80000,0x400080A8,}}
|
||||
#define __FLOATL_CONST_1e11__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x1DBA0000,0x40008DD2,}}
|
||||
#define __FLOATL_CONST_1e12__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xA5288000,0x40009B46,}}
|
||||
#define __FLOATL_CONST_1e13__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x27395000,0x4000A88C,}}
|
||||
#define __FLOATL_CONST_1e14__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3107A400,0x4000B5AF,}}
|
||||
#define __FLOATL_CONST_1e15__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFD498D00,0x4000C31A,}}
|
||||
#define __FLOATL_INT_ZERO__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#define __FLOATL_INF__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x7FFFFC00,}}
|
||||
#define __FLOATL_NAN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xFFFFFC00,}}
|
||||
#define __FLOATL_ALL_SIGN__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define __FLOATL_ALL_EXP__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x7FFFFC00,}}
|
||||
#define __FLOATL_ALL_MANT__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x000003FF,}}
|
||||
#define __FLOATL_ALL_EXP_MANT__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __FLOATL_HIDE_MANT_BIT__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00000400,}}
|
||||
#define __FLOATL_MANT_PLUS_MAX__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00002000,}}
|
||||
#define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x000007FF,}}
|
||||
#elif defined(FLOATL_USE_4096BITS)
|
||||
#define __FLOATL_BIT_PARTS__ 4096
|
||||
#define __FLOATL_U32_PARTS__ 128
|
||||
#define __FLOATL_U16_PARTS__ 256
|
||||
#define __FLOATL_EXP_BITS__ 23
|
||||
#define __FLOATL_MANT_BITS__ 4072
|
||||
#define __FLOATL_MANT_PARTS__ 127
|
||||
#define __FLOATL_MANT_HIGH_BITS__ 8
|
||||
#define __FLOATL_EXP_MID_VALUE__ 4194303
|
||||
#define __FLOATL_EXP_WHL_VALUE__ 8388607
|
||||
#define __FLOATL2_BIT_PARTS__ 8192
|
||||
#define __FLOATL2_U32_PARTS__ 256
|
||||
#define __FLOATL2_U16_PARTS__ 512
|
||||
#define __FLOATL_CONST_0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#define __FLOATL_CONST_1__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFFF00,}}
|
||||
#define __FLOATL_CONST_1e0__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x3FFFFF00,}}
|
||||
#define __FLOATL_CONST_1e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,0,0x2D000000,0x40001631,}}
|
||||
#define __FLOATL_CONST_1e8__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x78400000,0x4000197D,}}
|
||||
#define __FLOATL_CONST_1e9__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xD6500000,0x40001CDC,}}
|
||||
#define __FLOATL_CONST_1e10__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x05F20000,0x4000202A,}}
|
||||
#define __FLOATL_CONST_1e11__ (floatl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00000800,}}
|
||||
#define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x000001FF,}}
|
||||
#elif defined(FLOATL_USE_8192BITS)
|
||||
#define __FLOATL_BIT_PARTS__ 8192
|
||||
#define __FLOATL_U32_PARTS__ 256
|
||||
#define __FLOATL_U16_PARTS__ 512
|
||||
#define __FLOATL_EXP_BITS__ 25
|
||||
#define __FLOATL_MANT_BITS__ 8166
|
||||
#define __FLOATL_MANT_PARTS__ 255
|
||||
#define __FLOATL_MANT_HIGH_BITS__ 6
|
||||
#define __FLOATL_EXP_MID_VALUE__ 16777215
|
||||
#define __FLOATL_EXP_WHL_VALUE__ 33554431
|
||||
#define __FLOATL2_BIT_PARTS__ 16384
|
||||
#define __FLOATL2_U32_PARTS__ 512
|
||||
#define __FLOATL2_U16_PARTS__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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x00000200,}}
|
||||
#define __FLOATL_MANT_WHL__ (floatl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x0000007F,}}
|
||||
#endif
|
||||
/*****************************************************************/
|
||||
/* Config end */
|
||||
/*****************************************************************/
|
||||
|
||||
#if 0
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
/* Generate configuration [START] */
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t buffer[256];
|
||||
|
||||
uint32_t FLOATL_BIT_PARTS; // bits
|
||||
uint32_t FLOATL_U32_PARTS; // FLOATL_BIT_PARTS / 32 ---- FLOATL_BIT_PARTS >> 5
|
||||
uint32_t FLOATL_U16_PARTS; // FLOATL_BIT_PARTS / 16 ---- FLOATL_BIT_PARTS >> 4
|
||||
uint32_t FLOATL_EXP_BITS; // floatl_cfg_gen_exp(FLOATL_BIT_PARTS)
|
||||
uint32_t FLOATL_MANT_BITS; // FLOATL_BIT_PARTS - FLOATL_EXP_BITS - 1
|
||||
uint32_t FLOATL_MANT_PARTS; // FLOATL_MANT_BITS / 32 ---- FLOATL_MANT_BITS >> 5
|
||||
uint32_t FLOATL_MANT_HIGH_BITS; // FLOATL_MANT_BITS % 32 ---- FLOATL_MANT_BITS & 0x1F
|
||||
uint32_t FLOATL_EXP_MID_VALUE; // 2^(FLOATL_EXP_BITS-1) - 1
|
||||
uint32_t FLOATL_EXP_WHL_VALUE; // 2^(FLOATL_EXP_BITS) - 1
|
||||
|
||||
uint32_t FLOATL2_BIT_PARTS; // FLOATL_BIT_PARTS * 2
|
||||
uint32_t FLOATL2_U32_PARTS; // FLOATL2_BIT_PARTS / 32 ---- FLOATL2_BIT_PARTS >> 5
|
||||
uint32_t FLOATL2_U16_PARTS; // FLOATL2_BIT_PARTS / 16 ---- FLOATL2_BIT_PARTS >> 4
|
||||
} FLINFO;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t exp;
|
||||
char *mantBin;
|
||||
} FLCSTE; // const pow10(n)
|
||||
|
||||
static FLCSTE fle_list[] = {
|
||||
{.exp = 0, .mantBin = "0000000000000000000000000000000000000000000000000000"},
|
||||
{.exp = 3, .mantBin = "0100000000000000000000000000000000000000000000000000"},
|
||||
{.exp = 6, .mantBin = "1001000000000000000000000000000000000000000000000000"},
|
||||
{.exp = 9, .mantBin = "1111010000000000000000000000000000000000000000000000"},
|
||||
{.exp = 13, .mantBin = "0011100010000000000000000000000000000000000000000000"},
|
||||
{.exp = 16, .mantBin = "1000011010100000000000000000000000000000000000000000"},
|
||||
{.exp = 19, .mantBin = "1110100001001000000000000000000000000000000000000000"},
|
||||
{.exp = 23, .mantBin = "0011000100101101000000000000000000000000000000000000"},
|
||||
{.exp = 26, .mantBin = "0111110101111000010000000000000000000000000000000000"},
|
||||
{.exp = 29, .mantBin = "1101110011010110010100000000000000000000000000000000"},
|
||||
{.exp = 33, .mantBin = "0010101000000101111100100000000000000000000000000000"},
|
||||
{.exp = 36, .mantBin = "0111010010000111011011101000000000000000000000000000"},
|
||||
{.exp = 39, .mantBin = "1101000110101001010010100010000000000000000000000000"},
|
||||
{.exp = 43, .mantBin = "0010001100001001110011100101010000000000000000000000"},
|
||||
{.exp = 46, .mantBin = "0110101111001100010000011110100100000000000000000000"},
|
||||
{.exp = 49, .mantBin = "1100011010111111010100100110001101000000000000000000"},
|
||||
};
|
||||
|
||||
// e = 2.8625 * log2(bits) + 0.0111 * bits - 6.6730
|
||||
uint32_t floatl_cfg_gen_exp(uint32_t bits)
|
||||
{
|
||||
const int y = bits;
|
||||
int mantissa = 0;
|
||||
int exponent = 0;
|
||||
int sign = 1;
|
||||
|
||||
for (int i = y; i > 0; i--)
|
||||
{
|
||||
if (log2(i) * 2 < (y - i - 1))
|
||||
{
|
||||
mantissa = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
exponent = bits - sign - mantissa;
|
||||
|
||||
// printf("---------------- %d\r\n", bits);
|
||||
// printf("mantissa %d\r\n", mantissa);
|
||||
// printf("exponent %d\r\n", exponent);
|
||||
// printf("sign %d\r\n", sign);
|
||||
|
||||
// printf("high %d\r\n", mantissa & 0x1F); // % 32
|
||||
// printf("part %d\r\n", mantissa >> 5); // / 32
|
||||
|
||||
if (exponent >= 31) return 0;
|
||||
|
||||
return exponent;
|
||||
}
|
||||
|
||||
void floatl_cfg_const_out(FILE* file, FLINFO *info)
|
||||
{
|
||||
if (!file || !info) return;
|
||||
|
||||
fprintf(file, "(floatl){.u32={");
|
||||
for (int i = 0; i < info->FLOATL_U32_PARTS; i++)
|
||||
{
|
||||
uint32_t value = info->buffer[i];
|
||||
if (value == 0) fprintf(file, "0,");
|
||||
else if (value == 0xFFFFFFFF) fprintf(file, "-1,");
|
||||
else fprintf(file, "0x%08X,", value);
|
||||
}
|
||||
fprintf(file, "}}\n");
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_set_sign(FLINFO *info, int sign)
|
||||
{
|
||||
if (sign) info->buffer[info->FLOATL_U32_PARTS - 1] |= (1 << 31);
|
||||
else info->buffer[info->FLOATL_U32_PARTS - 1] &= ~(1 << 31);
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_set_exp_real(FLINFO *info, uint32_t t)
|
||||
{
|
||||
uint32_t temp = 1;
|
||||
|
||||
temp <<= info->FLOATL_EXP_BITS;
|
||||
temp -= 1;
|
||||
|
||||
t &= temp;
|
||||
t <<= (32 - info->FLOATL_EXP_BITS - 1);
|
||||
|
||||
temp <<= (32 - info->FLOATL_EXP_BITS - 1);
|
||||
|
||||
|
||||
info->buffer[info->FLOATL_U32_PARTS - 1] &= (~temp); // clear
|
||||
|
||||
info->buffer[info->FLOATL_U32_PARTS - 1] |= t;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_set_exp(FLINFO *info, int32_t e)
|
||||
{
|
||||
return floatl_cfg_set_exp_real(info, e + info->FLOATL_EXP_MID_VALUE);
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_set_mant(FLINFO *info, char *bin)
|
||||
{
|
||||
char *s = bin;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
int index = info->FLOATL_MANT_BITS - (s - bin) - 1;
|
||||
if (index < 0) break;
|
||||
if (index >= 0 && *s == '1')
|
||||
{
|
||||
int part = index / 32;
|
||||
int bit = index % 32;
|
||||
|
||||
info->buffer[part] |= (1 << bit);
|
||||
}
|
||||
s++;
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_int_zero(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_const_0(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_const_1(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
floatl_cfg_set_exp_real(info, 0xFFFFFFFF);
|
||||
info->buffer[info->FLOATL_U32_PARTS - 1] &= 0xBFFFFFFF;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_const_1eX(FLINFO *info, uint32_t e)
|
||||
{
|
||||
if (e >= sizeof(fle_list) / sizeof(fle_list[0])) return NULL;
|
||||
|
||||
memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
floatl_cfg_set_exp(info, fle_list[e].exp);
|
||||
floatl_cfg_set_mant(info, fle_list[e].mantBin);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_inf(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
floatl_cfg_set_exp_real(info, 0xFFFFFFFF);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_nan(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
floatl_cfg_set_exp_real(info, 0xFFFFFFFF);
|
||||
info->buffer[info->FLOATL_U32_PARTS - 1] |= 0x80000000;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_all_sign(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
info->buffer[info->FLOATL_U32_PARTS - 1] |= 0x80000000;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_all_exp(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
floatl_cfg_set_exp_real(info, 0xFFFFFFFF);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_all_mant(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, -1, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
floatl_cfg_set_exp_real(info, 0);
|
||||
info->buffer[info->FLOATL_U32_PARTS - 1] &= (~0x80000000);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_all_exp_mant(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, -1, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
info->buffer[info->FLOATL_U32_PARTS - 1] &= (~0x80000000);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_hide_mant_bit(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
floatl_cfg_set_exp_real(info, 1);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_mant_plus_max(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, 0, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
floatl_cfg_set_exp_real(info, 8);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
FLINFO *floatl_cfg_mant_whole(FLINFO *info)
|
||||
{
|
||||
memset(info->buffer, -1, info->FLOATL_U32_PARTS * sizeof(uint32_t));
|
||||
|
||||
floatl_cfg_set_exp_real(info, 1);
|
||||
info->buffer[info->FLOATL_U32_PARTS - 1] &= (~0x80000000);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
void floatl_cfg_generate(uint32_t bits, const char *filename)
|
||||
{
|
||||
#define MINBITS 64
|
||||
#define NEWLINE "\n" // "\r\n" //
|
||||
|
||||
FILE* output = stdout; // Default output to standard output
|
||||
if (filename != NULL)
|
||||
{
|
||||
output = fopen(filename, "w");
|
||||
if (output == NULL)
|
||||
{
|
||||
fprintf(stdout, "[ERROR] Failed to open output file"NEWLINE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* The number of bits in an floatl needs to be an exponent of two */
|
||||
if ((bits & (bits - 1)) != 0)
|
||||
{
|
||||
fprintf(stdout, "[ERROR] `bits` not a power of 2"NEWLINE);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Limiting the minimum bit */
|
||||
if (bits < MINBITS)
|
||||
{
|
||||
fprintf(stdout, "[ERROR] `bits` too small\r\b");
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
fprintf(output, "/* Config start */"NEWLINE);
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
|
||||
for (uint32_t tb = MINBITS; tb <= bits; tb <<= 1)
|
||||
{
|
||||
if (tb == MINBITS)
|
||||
{
|
||||
fprintf(output, "#define FLOATL_USE_%uBITS"NEWLINE, tb);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(output, "// #define FLOATL_USE_%uBITS"NEWLINE, tb);
|
||||
}
|
||||
}
|
||||
fprintf(output, NEWLINE);
|
||||
|
||||
floatl temp;
|
||||
|
||||
for (uint32_t tb = MINBITS; tb <= bits; tb <<= 1)
|
||||
{
|
||||
if (tb == MINBITS)
|
||||
{
|
||||
fprintf(output, "#if defined(FLOATL_USE_%uBITS)"NEWLINE, tb);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(output, "#elif defined(FLOATL_USE_%uBITS)"NEWLINE, tb);
|
||||
}
|
||||
|
||||
FLINFO info;
|
||||
info.FLOATL_BIT_PARTS = tb;
|
||||
info.FLOATL_U32_PARTS = info.FLOATL_BIT_PARTS >> (5);
|
||||
info.FLOATL_U16_PARTS = info.FLOATL_BIT_PARTS >> (4);
|
||||
info.FLOATL_EXP_BITS = floatl_cfg_gen_exp(info.FLOATL_BIT_PARTS);
|
||||
info.FLOATL_MANT_BITS = info.FLOATL_BIT_PARTS - info.FLOATL_EXP_BITS - 1;
|
||||
info.FLOATL_MANT_PARTS = info.FLOATL_MANT_BITS >> 5;
|
||||
info.FLOATL_MANT_HIGH_BITS = info.FLOATL_MANT_BITS & 0x1F;
|
||||
info.FLOATL_EXP_MID_VALUE = (uint32_t)pow(2, info.FLOATL_EXP_BITS - 1) - 1;
|
||||
info.FLOATL_EXP_WHL_VALUE = (uint32_t)pow(2, info.FLOATL_EXP_BITS) - 1;
|
||||
info.FLOATL2_BIT_PARTS = info.FLOATL_BIT_PARTS * 2;
|
||||
info.FLOATL2_U32_PARTS = info.FLOATL2_BIT_PARTS >> (5);
|
||||
info.FLOATL2_U16_PARTS = info.FLOATL2_BIT_PARTS >> (4);
|
||||
|
||||
fprintf(output, "#define __FLOATL_BIT_PARTS__ %u"NEWLINE, info.FLOATL_BIT_PARTS );
|
||||
fprintf(output, "#define __FLOATL_U32_PARTS__ %u"NEWLINE, info.FLOATL_U32_PARTS );
|
||||
fprintf(output, "#define __FLOATL_U16_PARTS__ %u"NEWLINE, info.FLOATL_U16_PARTS );
|
||||
fprintf(output, "#define __FLOATL_EXP_BITS__ %u"NEWLINE, info.FLOATL_EXP_BITS );
|
||||
fprintf(output, "#define __FLOATL_MANT_BITS__ %u"NEWLINE, info.FLOATL_MANT_BITS );
|
||||
fprintf(output, "#define __FLOATL_MANT_PARTS__ %u"NEWLINE, info.FLOATL_MANT_PARTS );
|
||||
fprintf(output, "#define __FLOATL_MANT_HIGH_BITS__ %u"NEWLINE, info.FLOATL_MANT_HIGH_BITS );
|
||||
fprintf(output, "#define __FLOATL_EXP_MID_VALUE__ %u"NEWLINE, info.FLOATL_EXP_MID_VALUE );
|
||||
fprintf(output, "#define __FLOATL_EXP_WHL_VALUE__ %u"NEWLINE, info.FLOATL_EXP_WHL_VALUE );
|
||||
|
||||
fprintf(output, "#define __FLOATL2_BIT_PARTS__ %u"NEWLINE, info.FLOATL2_BIT_PARTS );
|
||||
fprintf(output, "#define __FLOATL2_U32_PARTS__ %u"NEWLINE, info.FLOATL2_U32_PARTS );
|
||||
fprintf(output, "#define __FLOATL2_U16_PARTS__ %u"NEWLINE, info.FLOATL2_U16_PARTS );
|
||||
|
||||
fprintf(output, "#define __FLOATL_CONST_0__ "); floatl_cfg_const_out(output, floatl_cfg_const_0(&info) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1__ "); floatl_cfg_const_out(output, floatl_cfg_const_1(&info) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e0__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,0) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e1__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,1) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e2__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,2) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e3__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,3) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e4__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,4) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e5__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,5) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e6__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,6) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e7__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,7) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e8__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,8) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e9__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,9) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e10__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,10) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e11__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,11) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e12__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,12) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e13__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,13) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e14__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,14) );
|
||||
fprintf(output, "#define __FLOATL_CONST_1e15__ "); floatl_cfg_const_out(output, floatl_cfg_const_1eX(&info,15) );
|
||||
fprintf(output, "#define __FLOATL_INT_ZERO__ "); floatl_cfg_const_out(output, floatl_cfg_int_zero(&info) );
|
||||
fprintf(output, "#define __FLOATL_INF__ "); floatl_cfg_const_out(output, floatl_cfg_inf(&info) );
|
||||
fprintf(output, "#define __FLOATL_NAN__ "); floatl_cfg_const_out(output, floatl_cfg_nan(&info) );
|
||||
fprintf(output, "#define __FLOATL_ALL_SIGN__ "); floatl_cfg_const_out(output, floatl_cfg_all_sign(&info) );
|
||||
fprintf(output, "#define __FLOATL_ALL_EXP__ "); floatl_cfg_const_out(output, floatl_cfg_all_exp(&info) );
|
||||
fprintf(output, "#define __FLOATL_ALL_MANT__ "); floatl_cfg_const_out(output, floatl_cfg_all_mant(&info) );
|
||||
fprintf(output, "#define __FLOATL_ALL_EXP_MANT__ "); floatl_cfg_const_out(output, floatl_cfg_all_exp_mant(&info) );
|
||||
fprintf(output, "#define __FLOATL_HIDE_MANT_BIT__ "); floatl_cfg_const_out(output, floatl_cfg_hide_mant_bit(&info) );
|
||||
fprintf(output, "#define __FLOATL_MANT_PLUS_MAX__ "); floatl_cfg_const_out(output, floatl_cfg_mant_plus_max(&info) );
|
||||
fprintf(output, "#define __FLOATL_MANT_WHL__ "); floatl_cfg_const_out(output, floatl_cfg_mant_whole(&info) );
|
||||
}
|
||||
|
||||
fprintf(output, "#endif"NEWLINE);
|
||||
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
fprintf(output, "/* Config end */"NEWLINE);
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
|
||||
printf("\r\n\r\n-------------------------------------------------------------\r\n\r\n");
|
||||
|
||||
if (sizeof(temp) != (bits >> 3))
|
||||
{
|
||||
printf("[TODO] Apply the current configuration and run it again to get the new `FLOATL_MAX_DEC`\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("[INFO] The configuration has been generated, copy it to the `floatl_cfg.h` range specified\r\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
/* Generate configuration [END] */
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
113
source/07_math/intl.h
Normal file
113
source/07_math/intl.h
Normal file
@ -0,0 +1,113 @@
|
||||
|
||||
/*********************************************************************************************************
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* file description
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* \file intl.h
|
||||
* \unit intl
|
||||
* \brief This is a simple large inter number calculate module for C language
|
||||
* \author Lamdonn
|
||||
* \version v1.1.0
|
||||
* \license GPL-2.0
|
||||
* \copyright Copyright (C) 2023 Lamdonn.
|
||||
********************************************************************************************************/
|
||||
#ifndef __intl_H
|
||||
#define __intl_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "intl_cfg.h"
|
||||
|
||||
/* Version infomation */
|
||||
|
||||
#define INTL_V_MAJOR 1
|
||||
#define INTL_V_MINOR 1
|
||||
#define INTL_V_PATCH 0
|
||||
|
||||
/* Universal constant */
|
||||
|
||||
#define INTL_MAX __INTL_MAX__
|
||||
#define INTL_MIN __INTL_MIN__
|
||||
#define INTL_ZERO __INTL_ZERO__
|
||||
|
||||
/* Print the max buffer size, no width is specified in `intl_print` format */
|
||||
#define INTL_PRINT_MAX __INTL_P_MAX_BIN__
|
||||
|
||||
/* Error type */
|
||||
|
||||
#define INTL_E_DIV_0 0 // Division by zero
|
||||
#define INTL_E_INVALID_CAHRACTER 1 // Invalid character in input string
|
||||
|
||||
/**
|
||||
* \brief A structure to represent a long bits integer.
|
||||
*
|
||||
* This structure uses a union to store the long bits integer in two different ways:
|
||||
* - An array of `__INTL_U16_PARTS__` uint16_t values, allowing for operations on individual 16-bit segments.
|
||||
* - An array of `__INTL_U32_PARTS__` uint32_t values, providing a way to work with 32-bit segments.
|
||||
*
|
||||
* The union allows for flexibility in how the data is accessed and manipulated,
|
||||
* depending on the needs of the operations being performed.
|
||||
*/
|
||||
typedef struct {
|
||||
union {
|
||||
uint16_t u16[__INTL_U16_PARTS__]; ///< Array of uint16_t values representing the long bit integer in 16-bit segments.
|
||||
uint32_t u32[__INTL_U32_PARTS__]; ///< Array of uint32_t values representing the long bit integer in 32-bit segments.
|
||||
};
|
||||
} intl;
|
||||
|
||||
/**
|
||||
* \brief intl large integer api declaration, support for basic addition, subtraction, multiplication, division, etc.
|
||||
*/
|
||||
|
||||
intl intl_add(intl a, intl b);
|
||||
intl intl_sub(intl a, intl b);
|
||||
intl intl_mul(intl a, intl b);
|
||||
intl intl_div(intl a, intl b);
|
||||
intl intl_mod(intl a, intl b);
|
||||
intl intl_and(intl a, intl b);
|
||||
intl intl_xor(intl a, intl b);
|
||||
intl intl_or(intl a, intl b);
|
||||
intl intl_shl(intl a, uint32_t b);
|
||||
intl intl_shr(intl a, uint32_t b);
|
||||
intl intl_not(intl a);
|
||||
intl intl_abs(intl a);
|
||||
intl intl_inc(intl a);
|
||||
intl intl_dec(intl a);
|
||||
intl intl_neg(intl a);
|
||||
intl intl_from(const char *str);
|
||||
intl intl_from2(int value);
|
||||
int intl_print(intl a, char *buffer, uint32_t size, const char *format);
|
||||
int intl_lt(intl a, intl b);
|
||||
int intl_le(intl a, intl b);
|
||||
int intl_eq(intl a, intl b);
|
||||
int intl_ne(intl a, intl b);
|
||||
int intl_gt(intl a, intl b);
|
||||
int intl_ge(intl a, intl b);
|
||||
int intl_sign(intl a);
|
||||
|
||||
/**
|
||||
* \brief Converts a integer to an intl number.
|
||||
* \param[in] value: The integer to convert.
|
||||
* \return The corresponding intl number initialized with the given value.
|
||||
*/
|
||||
#define intl(value) intl_from2(value)
|
||||
|
||||
/**
|
||||
* \brief Converts an intl number to string.
|
||||
* \param[in] a: The intl number to convert.
|
||||
* \param[out] buffer: The buffer to store the resulting string.
|
||||
* It should be large enough to hold the representation.
|
||||
* \param[in] size: The size of buffer, can refer to `INTL_PRINT_MAX`.
|
||||
* \param[in] format: Printf-like format, [flags][width][type].
|
||||
* flags: '0' '-' '+' ' ' '#'
|
||||
* width: dec numeber
|
||||
* type: 'x' 'X' 'o' 'O' 'b' 'B' 'd' 'i' 'u'
|
||||
* \return String converted or "invalid" fail.
|
||||
*/
|
||||
#define intl_show(a, b, s, f) (intl_print((a), (b), (s), (f)) > 0 ? (b) : "invalid")
|
||||
|
||||
#endif
|
||||
|
||||
263
source/07_math/intl_cfg.h
Normal file
263
source/07_math/intl_cfg.h
Normal file
@ -0,0 +1,263 @@
|
||||
|
||||
/*********************************************************************************************************
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* file description
|
||||
* ------------------------------------------------------------------------------------------------------
|
||||
* \file intl_cfg.h
|
||||
* \unit intl
|
||||
* \brief This is a simple large int number calculate module config header file for C language
|
||||
* \author Lamdonn
|
||||
* \version v1.1.0
|
||||
* \license GPL-2.0
|
||||
* \copyright Copyright (C) 2023 Lamdonn.
|
||||
********************************************************************************************************/
|
||||
#ifndef __intl_cfg_H
|
||||
#define __intl_cfg_H
|
||||
|
||||
/* Error handling configuration */
|
||||
#define INTL_E(e, c) do { printf("[ERROR] Code %d,%c\r\n", (e), (c)); } while (0)
|
||||
// #define INTL_E(e, c)
|
||||
|
||||
/*
|
||||
* With this definition, you can configure the footprint size of an intl.
|
||||
* This is a flexible definition that can be extended to larger numbers in addition to the given few size definitions
|
||||
*/
|
||||
|
||||
/*****************************************************************/
|
||||
/* Config start */
|
||||
/*****************************************************************/
|
||||
// #define INTL_USE_64BITS
|
||||
// #define INTL_USE_128BITS
|
||||
// #define INTL_USE_256BITS
|
||||
#define INTL_USE_512BITS
|
||||
// #define INTL_USE_1024BITS
|
||||
// #define INTL_USE_2048BITS
|
||||
// #define INTL_USE_4096BITS
|
||||
// #define INTL_USE_8192BITS
|
||||
|
||||
#if defined(INTL_USE_64BITS)
|
||||
#define __INTL_BIT_PARTS__ 64
|
||||
#define __INTL_U32_PARTS__ 2
|
||||
#define __INTL_U16_PARTS__ 4
|
||||
#define __INTL_P_MAX_BIN__ 67
|
||||
#define __INTL_P_MAX_DEC__ 20
|
||||
#define __INTL_P_MAX_HEX__ 19
|
||||
#define __INTL_MAX__ (intl){.u32={-1,0x7FFFFFFF,}}
|
||||
#define __INTL_MIN__ (intl){.u32={0,0x80000000,}}
|
||||
#define __INTL_ZERO__ (intl){.u32={0,0,}}
|
||||
#elif defined(INTL_USE_128BITS)
|
||||
#define __INTL_BIT_PARTS__ 128
|
||||
#define __INTL_U32_PARTS__ 4
|
||||
#define __INTL_U16_PARTS__ 8
|
||||
#define __INTL_P_MAX_BIN__ 131
|
||||
#define __INTL_P_MAX_DEC__ 40
|
||||
#define __INTL_P_MAX_HEX__ 35
|
||||
#define __INTL_MAX__ (intl){.u32={-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __INTL_MIN__ (intl){.u32={0,0,0,0x80000000,}}
|
||||
#define __INTL_ZERO__ (intl){.u32={0,0,0,0,}}
|
||||
#elif defined(INTL_USE_256BITS)
|
||||
#define __INTL_BIT_PARTS__ 256
|
||||
#define __INTL_U32_PARTS__ 8
|
||||
#define __INTL_U16_PARTS__ 16
|
||||
#define __INTL_P_MAX_BIN__ 259
|
||||
#define __INTL_P_MAX_DEC__ 78
|
||||
#define __INTL_P_MAX_HEX__ 67
|
||||
#define __INTL_MAX__ (intl){.u32={-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __INTL_MIN__ (intl){.u32={0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define __INTL_ZERO__ (intl){.u32={0,0,0,0,0,0,0,0,}}
|
||||
#elif defined(INTL_USE_512BITS)
|
||||
#define __INTL_BIT_PARTS__ 512
|
||||
#define __INTL_U32_PARTS__ 16
|
||||
#define __INTL_U16_PARTS__ 32
|
||||
#define __INTL_P_MAX_BIN__ 515
|
||||
#define __INTL_P_MAX_DEC__ 155
|
||||
#define __INTL_P_MAX_HEX__ 131
|
||||
#define __INTL_MAX__ (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __INTL_MIN__ (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define __INTL_ZERO__ (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#elif defined(INTL_USE_1024BITS)
|
||||
#define __INTL_BIT_PARTS__ 1024
|
||||
#define __INTL_U32_PARTS__ 32
|
||||
#define __INTL_U16_PARTS__ 64
|
||||
#define __INTL_P_MAX_BIN__ 1027
|
||||
#define __INTL_P_MAX_DEC__ 309
|
||||
#define __INTL_P_MAX_HEX__ 259
|
||||
#define __INTL_MAX__ (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __INTL_MIN__ (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define __INTL_ZERO__ (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#elif defined(INTL_USE_2048BITS)
|
||||
#define __INTL_BIT_PARTS__ 2048
|
||||
#define __INTL_U32_PARTS__ 64
|
||||
#define __INTL_U16_PARTS__ 128
|
||||
#define __INTL_P_MAX_BIN__ 2051
|
||||
#define __INTL_P_MAX_DEC__ 618
|
||||
#define __INTL_P_MAX_HEX__ 515
|
||||
#define __INTL_MAX__ (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __INTL_MIN__ (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define __INTL_ZERO__ (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#elif defined(INTL_USE_4096BITS)
|
||||
#define __INTL_BIT_PARTS__ 4096
|
||||
#define __INTL_U32_PARTS__ 128
|
||||
#define __INTL_U16_PARTS__ 256
|
||||
#define __INTL_P_MAX_BIN__ 4099
|
||||
#define __INTL_P_MAX_DEC__ 1234
|
||||
#define __INTL_P_MAX_HEX__ 1027
|
||||
#define __INTL_MAX__ (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0x7FFFFFFF,}}
|
||||
#define __INTL_MIN__ (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x80000000,}}
|
||||
#define __INTL_ZERO__ (intl){.u32={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#elif defined(INTL_USE_8192BITS)
|
||||
#define __INTL_BIT_PARTS__ 8192
|
||||
#define __INTL_U32_PARTS__ 256
|
||||
#define __INTL_U16_PARTS__ 512
|
||||
#define __INTL_P_MAX_BIN__ 8195
|
||||
#define __INTL_P_MAX_DEC__ 2468
|
||||
#define __INTL_P_MAX_HEX__ 2051
|
||||
#define __INTL_MAX__ (intl){.u32={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}}
|
||||
#endif
|
||||
/*****************************************************************/
|
||||
/* Config end */
|
||||
/*****************************************************************/
|
||||
|
||||
#if 0 /* Config function */
|
||||
void intl_gen_cfg(uint32_t bits, const char *filename)
|
||||
{
|
||||
#define MINBITS 64
|
||||
#define NEWLINE "\n" // "\r\n" //
|
||||
|
||||
FILE* output = stdout; // Default output to standard output
|
||||
if (filename != NULL)
|
||||
{
|
||||
output = fopen(filename, "w");
|
||||
if (output == NULL)
|
||||
{
|
||||
fprintf(stdout, "[ERROR] Failed to open output file"NEWLINE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* The number of bits in an intl needs to be an exponent of two */
|
||||
if ((bits & (bits - 1)) != 0)
|
||||
{
|
||||
fprintf(stdout, "[ERROR] `bits` not a power of 2"NEWLINE);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Limiting the minimum bit */
|
||||
if (bits < MINBITS)
|
||||
{
|
||||
fprintf(stdout, "[ERROR] `bits` too small\r\b");
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
fprintf(output, "/* Config start */"NEWLINE);
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
|
||||
for (uint32_t tb = MINBITS; tb <= bits; tb <<= 1)
|
||||
{
|
||||
if (tb == bits)
|
||||
{
|
||||
fprintf(output, "#define INTL_USE_%uBITS"NEWLINE, tb);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(output, "// #define INTL_USE_%uBITS"NEWLINE, tb);
|
||||
}
|
||||
}
|
||||
fprintf(output, ""NEWLINE);
|
||||
|
||||
intl temp;
|
||||
|
||||
for (uint32_t tb = MINBITS; tb <= bits; tb <<= 1)
|
||||
{
|
||||
if (tb == MINBITS)
|
||||
{
|
||||
fprintf(output, "#if defined(INTL_USE_%uBITS)"NEWLINE, tb);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(output, "#elif defined(INTL_USE_%uBITS)"NEWLINE, tb);
|
||||
}
|
||||
|
||||
uint32_t BIT_PARTS ; /* bits */
|
||||
uint32_t U32_PARTS ; /* __INTL_BIT_PARTS__ / 32 */
|
||||
uint32_t U16_PARTS ; /* __INTL_BIT_PARTS__ / 16 */
|
||||
uint32_t MAX_BIN ; /* __INTL_BIT_PARTS__ + 1 */
|
||||
uint32_t MAX_DEC ; /* strlen(intl_shl(intl(1), __INTL_BIT_PARTS__ - 1)) + 1 */
|
||||
uint32_t MAX_HEX ; /* __INTL_BIT_PARTS__ / 4 + 1 */
|
||||
|
||||
BIT_PARTS = tb;
|
||||
U32_PARTS = BIT_PARTS >> (5);
|
||||
U16_PARTS = BIT_PARTS >> (4);
|
||||
MAX_BIN = BIT_PARTS + 3; // "0b" + '\0'
|
||||
MAX_DEC = MAX_BIN; // First apply as MAX bin maximum value, and then according to the actual calculation
|
||||
MAX_HEX = (BIT_PARTS >> (2)) + 3; // "0x" + '\0'
|
||||
|
||||
/* The current configuration is applied */
|
||||
if (sizeof(temp) == (bits >> 3))
|
||||
{
|
||||
char buffer[__INTL_P_MAX_BIN__];
|
||||
MAX_DEC = intl_print(intl_shl(intl(1), BIT_PARTS - 1), buffer, sizeof(buffer), "d") + 1; // '\0'
|
||||
}
|
||||
|
||||
fprintf(output, "#define __INTL_BIT_PARTS__ %u"NEWLINE, BIT_PARTS);
|
||||
fprintf(output, "#define __INTL_U32_PARTS__ %u"NEWLINE, U32_PARTS);
|
||||
fprintf(output, "#define __INTL_U16_PARTS__ %u"NEWLINE, U16_PARTS);
|
||||
fprintf(output, "#define __INTL_P_MAX_BIN__ %u"NEWLINE, MAX_BIN);
|
||||
fprintf(output, "#define __INTL_P_MAX_DEC__ %u"NEWLINE, MAX_DEC);
|
||||
fprintf(output, "#define __INTL_P_MAX_HEX__ %u"NEWLINE, MAX_HEX);
|
||||
|
||||
/* __INTL_MAX__ */
|
||||
fprintf(output, "#define __INTL_MAX__ (intl){.u32={");
|
||||
for (uint32_t i = 0; i < U32_PARTS; i++)
|
||||
{
|
||||
fprintf(output, "%s,", (i == U32_PARTS-1) ? "0x7FFFFFFF" : "-1");
|
||||
}
|
||||
fprintf(output, "}}"NEWLINE);
|
||||
|
||||
/* __INTL_MIN__ */
|
||||
fprintf(output, "#define __INTL_MIN__ (intl){.u32={");
|
||||
for (uint32_t i = 0; i < U32_PARTS; i++)
|
||||
{
|
||||
fprintf(output, "%s,", (i == U32_PARTS-1) ? "0x80000000" : "0");
|
||||
}
|
||||
fprintf(output, "}}"NEWLINE);
|
||||
|
||||
/* __INTL_ZERO__ */
|
||||
fprintf(output, "#define __INTL_ZERO__ (intl){.u32={");
|
||||
for (uint32_t i = 0; i < U32_PARTS; i++)
|
||||
{
|
||||
fprintf(output, "0,");
|
||||
}
|
||||
fprintf(output, "}}"NEWLINE);
|
||||
}
|
||||
|
||||
fprintf(output, "#endif"NEWLINE);
|
||||
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
fprintf(output, "/* Config end */"NEWLINE);
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
|
||||
fprintf(stdout, "\r\n\r\n-------------------------------------------------------------\r\n"NEWLINE);
|
||||
|
||||
/* The current configuration is not applied */
|
||||
if (sizeof(temp) != (bits >> 3))
|
||||
{
|
||||
fprintf(stdout, "[TODO][%s] Apply the current configuration and run it again to get the new `__INTL_P_MAX_DEC__`"NEWLINE, filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stdout, "[INFO][%s] The configuration has been generated, copy it to the `intl_cfg.h` range specified"NEWLINE, filename);
|
||||
}
|
||||
|
||||
if (filename != NULL)
|
||||
{
|
||||
fclose(output);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -37,8 +37,9 @@ TEST_LIST += sList
|
||||
TEST_LIST += dList
|
||||
TEST_LIST += cQueue
|
||||
TEST_LIST += intl
|
||||
TEST_LIST += floatl
|
||||
TEST_LIST += ramt
|
||||
TEST_LIST += romt
|
||||
TEST_LIST += cpul
|
||||
# TEST_LIST += cpul
|
||||
TEST_LIST += date
|
||||
TEST_LIST += unitt
|
||||
|
||||
1470
test/test_floatl.c
Normal file
1470
test/test_floatl.c
Normal file
File diff suppressed because it is too large
Load Diff
382
test/test_intl.c
382
test/test_intl.c
@ -12,6 +12,8 @@
|
||||
#include "intl.h"
|
||||
#endif
|
||||
|
||||
static char pbuff[INTL_PRINT_MAX] = {0};
|
||||
|
||||
/************************************************************************************/
|
||||
/************************************* Unit Test ************************************/
|
||||
/************************************************************************************/
|
||||
@ -19,13 +21,86 @@
|
||||
// #define EXIT_TEST
|
||||
extern uint64_t unitt_clock(void);
|
||||
|
||||
static int test_0(void)
|
||||
static intl random_intl()
|
||||
{
|
||||
intl random = INTL_ZERO;
|
||||
|
||||
for (int i = 0; i < __INTL_U32_PARTS__; i++)
|
||||
{
|
||||
random.u32[i] = rand();
|
||||
}
|
||||
|
||||
return random;
|
||||
}
|
||||
|
||||
static const char* random_format()
|
||||
{
|
||||
const char *format[4] = { "d", "#b", "#o", "#x" };
|
||||
return format[rand() % 4];
|
||||
}
|
||||
|
||||
static int test_convert(void)
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (0)
|
||||
intl src = random_intl();
|
||||
intl dst = intl_from(intl_show(src, pbuff, sizeof(pbuff), random_format()));
|
||||
|
||||
if (!intl_eq(src, dst))
|
||||
{
|
||||
|
||||
printf("convert fail: \r\n");
|
||||
printf("src: %s\r\n", intl_show(src, pbuff, sizeof(pbuff), "x"));
|
||||
printf("dst: %s\r\n", intl_show(dst, pbuff, sizeof(pbuff), "x"));
|
||||
#if defined (EXIT_TEST)
|
||||
exit(0);
|
||||
#endif
|
||||
return UNITT_E_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return UNITT_E_OK;
|
||||
}
|
||||
|
||||
/* Need config intl as 64bits */
|
||||
static int test_accuracy(void)
|
||||
{
|
||||
for (int i = 0; i < 1000; i++)
|
||||
{
|
||||
int op = rand() % 10;
|
||||
uint8_t sh = 0;
|
||||
|
||||
intl a = random_intl();
|
||||
intl b = random_intl();
|
||||
intl c = INTL_ZERO;
|
||||
|
||||
int64_t x = 0;
|
||||
int64_t y = 0;
|
||||
int64_t z = 0;
|
||||
|
||||
memcpy(&x, &a, sizeof(x));
|
||||
memcpy(&y, &b, sizeof(y));
|
||||
|
||||
/* Skip the division by 0 */
|
||||
if (op == 3 && y == 0) continue;
|
||||
/* Adjust shift */
|
||||
if (op == 8 || op == 9) { sh = y; sh %= 64; }
|
||||
|
||||
if (op == 0) { c = intl_add(a, b); z = x + y; }
|
||||
else if (op == 1) { c = intl_sub(a, b); z = x - y; }
|
||||
else if (op == 2) { c = intl_mul(a, b); z = x * y; }
|
||||
else if (op == 3) { c = intl_div(a, b); z = x / y; }
|
||||
else if (op == 4) { c = intl_mod(a, b); z = x % y; }
|
||||
else if (op == 5) { c = intl_and(a, b); z = x & y; }
|
||||
else if (op == 6) { c = intl_xor(a, b); z = x ^ y; }
|
||||
else if (op == 7) { c = intl_or (a, b); z = x | y; }
|
||||
else if (op == 8) { c = intl_shl(a, sh); z = x << sh; }
|
||||
else if (op == 9) { c = intl_shr(a, sh); z = x >> sh; }
|
||||
|
||||
if (memcmp(&c, &z, sizeof(z)) != 0)
|
||||
{
|
||||
printf("accuracy fail: %d,%d\r\n", op, sh);
|
||||
printf("c: %s\r\n", intl_show(c, pbuff, sizeof(pbuff), "d"));
|
||||
printf("z: %lld\r\n", z);
|
||||
#if defined (EXIT_TEST)
|
||||
exit(0);
|
||||
#endif
|
||||
@ -39,13 +114,14 @@ static int test_0(void)
|
||||
static void unitt_task(void)
|
||||
{
|
||||
static UNITT_TCASE rand_tests[] = {
|
||||
UNITT_TCASE(test_0),
|
||||
// UNITT_TCASE(test_1),
|
||||
// UNITT_TCASE(test_2),
|
||||
UNITT_TCASE(test_convert),
|
||||
#if defined (INTL_USE_64BITS)
|
||||
UNITT_TCASE(test_accuracy),
|
||||
#endif
|
||||
};
|
||||
|
||||
static UNITT suites[] = {
|
||||
{ "xxx suite", rand_tests, sizeof(rand_tests) / sizeof(rand_tests[0]) , unitt_clock },
|
||||
{ "intl suite", rand_tests, sizeof(rand_tests) / sizeof(rand_tests[0]) , unitt_clock },
|
||||
};
|
||||
|
||||
UNITT_EXE(suites);
|
||||
@ -55,16 +131,141 @@ static void unitt_task(void)
|
||||
/************************************* Base Test ************************************/
|
||||
/************************************************************************************/
|
||||
|
||||
#define INTL_P_DEC 0x01
|
||||
#define INTL_P_BIN 0x02
|
||||
#define INTL_P_HEX 0x04
|
||||
|
||||
static void print_intl(intl a, uint8_t type)
|
||||
void intl_gen_cfg(uint32_t bits, const char *filename)
|
||||
{
|
||||
char buffer[INTL_MAX_BIN];
|
||||
if (type & INTL_P_DEC) printf("intl (decimal): %s\n", intl_sdec(a, buffer));
|
||||
if (type & INTL_P_HEX) printf("intl (hex): %s\n", intl_shex(a, buffer));
|
||||
if (type & INTL_P_BIN) printf("intl (bin): %s\n", intl_sbin(a, buffer));
|
||||
#define MINBITS 64
|
||||
#define NEWLINE "\n" // "\r\n" //
|
||||
|
||||
FILE* output = stdout; // Default output to standard output
|
||||
if (filename != NULL)
|
||||
{
|
||||
output = fopen(filename, "w");
|
||||
if (output == NULL)
|
||||
{
|
||||
fprintf(stdout, "[ERROR] Failed to open output file"NEWLINE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* The number of bits in an intl needs to be an exponent of two */
|
||||
if ((bits & (bits - 1)) != 0)
|
||||
{
|
||||
fprintf(stdout, "[ERROR] `bits` not a power of 2"NEWLINE);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Limiting the minimum bit */
|
||||
if (bits < MINBITS)
|
||||
{
|
||||
fprintf(stdout, "[ERROR] `bits` too small\r\b");
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
fprintf(output, "/* Config start */"NEWLINE);
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
|
||||
for (uint32_t tb = MINBITS; tb <= bits; tb <<= 1)
|
||||
{
|
||||
if (tb == bits)
|
||||
{
|
||||
fprintf(output, "#define INTL_USE_%uBITS"NEWLINE, tb);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(output, "// #define INTL_USE_%uBITS"NEWLINE, tb);
|
||||
}
|
||||
}
|
||||
fprintf(output, ""NEWLINE);
|
||||
|
||||
intl temp;
|
||||
|
||||
for (uint32_t tb = MINBITS; tb <= bits; tb <<= 1)
|
||||
{
|
||||
if (tb == MINBITS)
|
||||
{
|
||||
fprintf(output, "#if defined(INTL_USE_%uBITS)"NEWLINE, tb);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(output, "#elif defined(INTL_USE_%uBITS)"NEWLINE, tb);
|
||||
}
|
||||
|
||||
uint32_t BIT_PARTS ; /* bits */
|
||||
uint32_t U32_PARTS ; /* __INTL_BIT_PARTS__ / 32 */
|
||||
uint32_t U16_PARTS ; /* __INTL_BIT_PARTS__ / 16 */
|
||||
uint32_t MAX_BIN ; /* __INTL_BIT_PARTS__ + 1 */
|
||||
uint32_t MAX_DEC ; /* strlen(intl_shl(intl(1), __INTL_BIT_PARTS__ - 1)) + 1 */
|
||||
uint32_t MAX_HEX ; /* __INTL_BIT_PARTS__ / 4 + 1 */
|
||||
|
||||
BIT_PARTS = tb;
|
||||
U32_PARTS = BIT_PARTS >> (5);
|
||||
U16_PARTS = BIT_PARTS >> (4);
|
||||
MAX_BIN = BIT_PARTS + 3; // "0b" + '\0'
|
||||
MAX_DEC = MAX_BIN; // First apply as MAX bin maximum value, and then according to the actual calculation
|
||||
MAX_HEX = (BIT_PARTS >> (2)) + 3; // "0x" + '\0'
|
||||
|
||||
/* The current configuration is applied */
|
||||
if (sizeof(temp) == (bits >> 3))
|
||||
{
|
||||
char buffer[__INTL_P_MAX_BIN__];
|
||||
MAX_DEC = intl_print(intl_shl(intl(1), BIT_PARTS - 1), buffer, sizeof(buffer), "d") + 1; // '\0'
|
||||
}
|
||||
|
||||
fprintf(output, "#define __INTL_BIT_PARTS__ %u"NEWLINE, BIT_PARTS);
|
||||
fprintf(output, "#define __INTL_U32_PARTS__ %u"NEWLINE, U32_PARTS);
|
||||
fprintf(output, "#define __INTL_U16_PARTS__ %u"NEWLINE, U16_PARTS);
|
||||
fprintf(output, "#define __INTL_P_MAX_BIN__ %u"NEWLINE, MAX_BIN);
|
||||
fprintf(output, "#define __INTL_P_MAX_DEC__ %u"NEWLINE, MAX_DEC);
|
||||
fprintf(output, "#define __INTL_P_MAX_HEX__ %u"NEWLINE, MAX_HEX);
|
||||
|
||||
/* __INTL_MAX__ */
|
||||
fprintf(output, "#define __INTL_MAX__ (intl){.u32={");
|
||||
for (uint32_t i = 0; i < U32_PARTS; i++)
|
||||
{
|
||||
fprintf(output, "%s,", (i == U32_PARTS-1) ? "0x7FFFFFFF" : "-1");
|
||||
}
|
||||
fprintf(output, "}}"NEWLINE);
|
||||
|
||||
/* __INTL_MIN__ */
|
||||
fprintf(output, "#define __INTL_MIN__ (intl){.u32={");
|
||||
for (uint32_t i = 0; i < U32_PARTS; i++)
|
||||
{
|
||||
fprintf(output, "%s,", (i == U32_PARTS-1) ? "0x80000000" : "0");
|
||||
}
|
||||
fprintf(output, "}}"NEWLINE);
|
||||
|
||||
/* __INTL_ZERO__ */
|
||||
fprintf(output, "#define __INTL_ZERO__ (intl){.u32={");
|
||||
for (uint32_t i = 0; i < U32_PARTS; i++)
|
||||
{
|
||||
fprintf(output, "0,");
|
||||
}
|
||||
fprintf(output, "}}"NEWLINE);
|
||||
}
|
||||
|
||||
fprintf(output, "#endif"NEWLINE);
|
||||
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
fprintf(output, "/* Config end */"NEWLINE);
|
||||
fprintf(output, "/*****************************************************************/"NEWLINE);
|
||||
|
||||
fprintf(stdout, "\r\n\r\n-------------------------------------------------------------\r\n"NEWLINE);
|
||||
|
||||
/* The current configuration is not applied */
|
||||
if (sizeof(temp) != (bits >> 3))
|
||||
{
|
||||
fprintf(stdout, "[TODO][%s] Apply the current configuration and run it again to get the new `__INTL_P_MAX_DEC__`"NEWLINE, filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stdout, "[INFO][%s] The configuration has been generated, copy it to the `intl_cfg.h` range specified"NEWLINE, filename);
|
||||
}
|
||||
|
||||
if (filename != NULL)
|
||||
{
|
||||
fclose(output);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_define(void)
|
||||
@ -91,9 +292,23 @@ static void test_print(void)
|
||||
{
|
||||
intl a = intl_from("123456789123456789123456789");
|
||||
|
||||
print_intl(a, INTL_P_DEC);
|
||||
print_intl(a, INTL_P_BIN);
|
||||
print_intl(a, INTL_P_HEX);
|
||||
printf("a: %s\r\n", intl_show(a, pbuff, sizeof(pbuff), "dx"));
|
||||
printf("a: %s\r\n", intl_show(INTL_ZERO, pbuff, sizeof(pbuff), "#x"));
|
||||
printf("a: %s\r\n", intl_show(a, pbuff, sizeof(pbuff), "#o"));
|
||||
printf("a: %s\r\n", intl_show(a, pbuff, sizeof(pbuff), "#x"));
|
||||
printf("a: %s\r\n", intl_show(intl(123456), pbuff, sizeof(pbuff), "10x"));
|
||||
printf("a: %s\r\n", intl_show(intl(123456), pbuff, sizeof(pbuff), "010x"));
|
||||
printf("a: %s\r\n", intl_show(intl(123456), pbuff, sizeof(pbuff), "-10x"));
|
||||
printf("a: %s\r\n", intl_show(intl(123456), pbuff, sizeof(pbuff), "-010x"));
|
||||
printf("a: %s\r\n", intl_show(intl(123456), pbuff, sizeof(pbuff), "#10x"));
|
||||
printf("a: %s\r\n", intl_show(intl(123456), pbuff, sizeof(pbuff), "#010x"));
|
||||
printf("a: %s\r\n", intl_show(intl(123456), pbuff, sizeof(pbuff), "#-10x"));
|
||||
printf("a: %s\r\n", intl_show(intl(123456), pbuff, sizeof(pbuff), "#-010x"));
|
||||
printf("a: %s\r\n", intl_show(intl(123456), pbuff, sizeof(pbuff), "#x"));
|
||||
printf("a: %s\r\n", intl_show(intl(123456), pbuff, sizeof(pbuff), "#0x"));
|
||||
printf("a: %s\r\n", intl_show(intl(-123456), pbuff, sizeof(pbuff), "#d"));
|
||||
printf("a: %s\r\n", intl_show(intl(-123456), pbuff, sizeof(pbuff), "#10d"));
|
||||
printf("a: %s\r\n", intl_show(intl(-123456), pbuff, sizeof(pbuff), "-#d"));
|
||||
}
|
||||
|
||||
static void test_calculate(void)
|
||||
@ -101,51 +316,27 @@ static void test_calculate(void)
|
||||
intl a = intl_from("123456789123456789123456789");
|
||||
intl b = intl_from("987654321987654321987654321");
|
||||
|
||||
printf("a: \r\n");
|
||||
print_intl(a, INTL_P_DEC);
|
||||
printf("b: \r\n");
|
||||
print_intl(b, INTL_P_DEC);
|
||||
|
||||
printf("a + b: \r\n");
|
||||
print_intl(intl_add(a, b), INTL_P_DEC);
|
||||
|
||||
printf("a - b: \r\n");
|
||||
print_intl(intl_sub(a, b), INTL_P_DEC);
|
||||
|
||||
printf("a * b: \r\n");
|
||||
print_intl(intl_mul(a, b), INTL_P_DEC);
|
||||
|
||||
printf("b / a: \r\n");
|
||||
print_intl(intl_div(b, a), INTL_P_DEC);
|
||||
|
||||
printf("b %% a: \r\n");
|
||||
print_intl(intl_mod(b, a), INTL_P_DEC);
|
||||
|
||||
printf("a & b: \r\n");
|
||||
print_intl(intl_and(a, b), INTL_P_DEC);
|
||||
|
||||
printf("a | b: \r\n");
|
||||
print_intl(intl_or(a, b), INTL_P_DEC);
|
||||
|
||||
printf("a ^ b: \r\n");
|
||||
print_intl(intl_xor(a, b), INTL_P_DEC);
|
||||
|
||||
printf("~a: \r\n");
|
||||
print_intl(intl_not(a), INTL_P_DEC);
|
||||
|
||||
printf("a << 1: \r\n");
|
||||
print_intl(intl_shl(a, 1), INTL_P_DEC);
|
||||
|
||||
printf("b >> 1: \r\n");
|
||||
print_intl(intl_shr(b, 1), INTL_P_DEC);
|
||||
|
||||
printf("compare: %d\r\n", intl_cmp(a, b));
|
||||
|
||||
printf("a incremented: \r\n");
|
||||
print_intl(intl_inc(a), INTL_P_DEC);
|
||||
|
||||
printf("b decremented: \r\n");
|
||||
print_intl(intl_dec(b), INTL_P_DEC);
|
||||
printf("a: %s\r\n", intl_show(a, pbuff, sizeof(pbuff), "d"));
|
||||
printf("b: %s\r\n", intl_show(b, pbuff, sizeof(pbuff), "d"));
|
||||
printf("a + b: %s\r\n", intl_show(intl_add(a, b), pbuff, sizeof(pbuff), "d"));
|
||||
printf("a - b: %s\r\n", intl_show(intl_sub(a, b), pbuff, sizeof(pbuff), "d"));
|
||||
printf("a * b: %s\r\n", intl_show(intl_mul(a, b), pbuff, sizeof(pbuff), "d"));
|
||||
printf("b / a: %s\r\n", intl_show(intl_div(a, b), pbuff, sizeof(pbuff), "d"));
|
||||
printf("b %% a: %s\r\n", intl_show(intl_mod(a, b), pbuff, sizeof(pbuff), "d"));
|
||||
printf("a & b: %s\r\n", intl_show(intl_and(a, b), pbuff, sizeof(pbuff), "d"));
|
||||
printf("a | b: %s\r\n", intl_show(intl_or(a, b), pbuff, sizeof(pbuff), "d"));
|
||||
printf("a ^ b: %s\r\n", intl_show(intl_xor(a, b), pbuff, sizeof(pbuff), "d"));
|
||||
printf("~a: %s\r\n", intl_show(intl_not(a), pbuff, sizeof(pbuff), "d"));
|
||||
printf("a << 1: %s\r\n", intl_show(intl_shl(a, 1), pbuff, sizeof(pbuff), "d"));
|
||||
printf("b >> 1: %s\r\n", intl_show(intl_shr(a, 1), pbuff, sizeof(pbuff), "d"));
|
||||
printf("a++: %s\r\n", intl_show(intl_inc(a), pbuff, sizeof(pbuff), "d"));
|
||||
printf("b--: %s\r\n", intl_show(intl_dec(a), pbuff, sizeof(pbuff), "d"));
|
||||
printf("a > b: %d\r\n", intl_gt(a, b));
|
||||
printf("a >= b: %d\r\n", intl_ge(a, b));
|
||||
printf("a < b: %d\r\n", intl_lt(a, b));
|
||||
printf("a <= b: %d\r\n", intl_le(a, b));
|
||||
printf("a == b: %d\r\n", intl_eq(a, b));
|
||||
printf("a != b: %d\r\n", intl_ne(a, b));
|
||||
}
|
||||
|
||||
static void test_base(void)
|
||||
@ -168,6 +359,15 @@ static void usage(void)
|
||||
" -e <execute> Specifies the function to execute, the default is the <base> test\n"
|
||||
" <base> Test base function\n"
|
||||
" <ut> Unit test\n"
|
||||
" <define> Test define function\n"
|
||||
" <cal> Calculate string math expression\n"
|
||||
" <gen> Generate the intl configuration file code segment, need specify -f -b\n"
|
||||
" <print> Print an intl number\n"
|
||||
" -l <format> Format string, 10d, 08x, ...\n"
|
||||
" -o <op function> Operate function, add, sub, mul, div, ...\n"
|
||||
" -n <intl> intl number expression\n"
|
||||
" -f <filename> File name, temporarily store configuration code segment\n"
|
||||
" -b <bits> Maximum number of configured bits\n"
|
||||
" -h Print help\n"
|
||||
" -v Print version\n"
|
||||
" -u [<period>] Unit test period, unit ms, the default is 1000ms\n"
|
||||
@ -180,17 +380,39 @@ static int test(int argc, char *argv[])
|
||||
{
|
||||
char *execute = NULL;
|
||||
int ut_period = 1000;
|
||||
char *filename = NULL;
|
||||
int bits = 0;
|
||||
|
||||
intl n[2] = {INTL_ZERO, INTL_ZERO};
|
||||
int in = 0;
|
||||
char *op = NULL;
|
||||
char *format = NULL;
|
||||
|
||||
/* reset getopt */
|
||||
command_opt_init();
|
||||
|
||||
while (1)
|
||||
{
|
||||
int opt = command_getopt(argc, argv, "e:hvu::");
|
||||
int opt = command_getopt(argc, argv, "e:hvu::f:b:n:o:l:");
|
||||
if (opt == -1) break;
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
case 'l' :
|
||||
format = command_optarg;
|
||||
break;
|
||||
case 'o' :
|
||||
op = command_optarg;
|
||||
break;
|
||||
case 'n' :
|
||||
if (in < 2) n[in++] = intl_from(command_optarg);
|
||||
break;
|
||||
case 'b' :
|
||||
bits = atoi(command_optarg);
|
||||
break;
|
||||
case 'f' :
|
||||
filename = command_optarg;
|
||||
break;
|
||||
case 'u' :
|
||||
if (command_optarg) ut_period = atoi(command_optarg);
|
||||
break;
|
||||
@ -229,6 +451,36 @@ static int test(int argc, char *argv[])
|
||||
printf("create task %d\r\n", task_create(ut_period, unitt_task));
|
||||
#endif
|
||||
}
|
||||
else if (!strcmp(execute, "define"))
|
||||
{
|
||||
test_define();
|
||||
}
|
||||
else if (!strcmp(execute, "gen"))
|
||||
{
|
||||
intl_gen_cfg(bits, filename);
|
||||
}
|
||||
else if (!strcmp(execute, "cal"))
|
||||
{
|
||||
intl result = INTL_ZERO;
|
||||
|
||||
if (!strcmp(op, "add")) result = intl_add(n[0], n[1]);
|
||||
else if (!strcmp(op, "sub")) result = intl_sub(n[0], n[1]);
|
||||
else if (!strcmp(op, "mul")) result = intl_mul(n[0], n[1]);
|
||||
else if (!strcmp(op, "div")) result = intl_div(n[0], n[1]);
|
||||
else if (!strcmp(op, "mod")) result = intl_mod(n[0], n[1]);
|
||||
else if (!strcmp(op, "and")) result = intl_and(n[0], n[1]);
|
||||
else if (!strcmp(op, "xor")) result = intl_xor(n[0], n[1]);
|
||||
else if (!strcmp(op, "or")) result = intl_or(n[0], n[1]);
|
||||
else if (!strcmp(op, "shl")) result = intl_shl(n[0], *(uint32_t *)(&n[1]));
|
||||
else if (!strcmp(op, "shr")) result = intl_shr(n[0], *(uint32_t *)(&n[1]));
|
||||
else printf("No such function!\r\n");
|
||||
|
||||
printf("result: %s\r\n", intl_show(result, pbuff, sizeof(pbuff), "d"));
|
||||
}
|
||||
else if (!strcmp(execute, "print"))
|
||||
{
|
||||
printf("%s\r\n", intl_show(n[0], pbuff, sizeof(pbuff), format));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user