Skip to content

Commit 66b6544

Browse files
committed
Fixes #84: Choice of float/double
* Can now choose between using `double` and `float` internally, for floating-point work, using the `PRINTF_USE_DOUBLE_INTERNALLY` definition and corresponding CMake option. * Adjusted test suite to support the different choice of floating-point type: * Tests relevant both to `float` and `double`, but with different precisions, are adjusted with an `#if #else #endif` * Tests and test cases relevant only for `double` precision are not compiled at all when `float` is used. * Lots of new explicit conversions :-(
1 parent 10aca98 commit 66b6544

File tree

4 files changed

+181
-105
lines changed

4 files changed

+181
-105
lines changed

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ option(SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS "Support the I + bit size integer
2121
option(SUPPORT_WRITEBACK_SPECIFIER "Support the length write-back specifier (%n)" ON)
2222
option(SUPPORT_LONG_LONG "Support long long integral types (allows for the ll length modifier and affects %p)" ON)
2323
option(ALIAS_STANDARD_FUNCTION_NAMES "Alias the standard library function names (printf, sprintf etc.) to the library's functions" ON)
24+
option(USE_DOUBLE_INTERNALLY "Use the C `double` type - typically 64-bit in size - for internal floating-point arithmetic " ON)
2425

2526
foreach(opt
2627
SUPPORT_DECIMAL_SPECIFIERS
2728
SUPPORT_EXPONENTIAL_SPECIFIERS
2829
SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS
2930
SUPPORT_WRITEBACK_SPECIFIER
3031
SUPPORT_LONG_LONG
31-
ALIAS_STANDARD_FUNCTION_NAMES)
32+
ALIAS_STANDARD_FUNCTION_NAMES
33+
USE_DOUBLE_INTERNALLY
34+
)
3235
if (${${opt}})
3336
set("PRINTF_${opt}" 1)
3437
else()

printf_config.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define PRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS @PRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS@
99
#define PRINTF_SUPPORT_LONG_LONG @PRINTF_SUPPORT_LONG_LONG@
1010
#define PRINTF_ALIAS_STANDARD_FUNCTION_NAMES @PRINTF_ALIAS_STANDARD_FUNCTION_NAMES@
11+
#define PRINTF_USE_DOUBLE_INTERNALLY @PRINTF_USE_DOUBLE_INTERNALLY@
1112

1213
#define PRINTF_INTEGER_BUFFER_SIZE @PRINTF_INTEGER_BUFFER_SIZE@
1314
#define PRINTF_DECIMAL_BUFFER_SIZE @PRINTF_DECIMAL_BUFFER_SIZE@

0 commit comments

Comments
 (0)