Skip to content

Commit

Permalink
Fixes #84: Choice of float/double
Browse files Browse the repository at this point in the history
* 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 :-(
  • Loading branch information
eyalroz committed Feb 7, 2022
1 parent 6e16e71 commit 83f5811
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 102 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ option(SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS "Support the I + bit size integer
option(SUPPORT_WRITEBACK_SPECIFIER "Support the length write-back specifier (%n)" ON)
option(SUPPORT_LONG_LONG "Support long long integral types (allows for the ll length modifier and affects %p)" ON)
option(ALIAS_STANDARD_FUNCTION_NAMES "Alias the standard library function names (printf, sprintf etc.) to the library's functions" ON)
option(USE_DOUBLE_INTERNALLY "Use the C `double` type - typically 64-bit in size - for internal floating-point arithmetic " ON)

foreach(opt
SUPPORT_DECIMAL_SPECIFIERS
SUPPORT_EXPONENTIAL_SPECIFIERS
SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS
SUPPORT_WRITEBACK_SPECIFIER
SUPPORT_LONG_LONG
ALIAS_STANDARD_FUNCTION_NAMES)
ALIAS_STANDARD_FUNCTION_NAMES
USE_DOUBLE_INTERNALLY
)
if (${${opt}})
set("PRINTF_${opt}" 1)
else()
Expand Down
1 change: 1 addition & 0 deletions printf_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define PRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS @PRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS@
#define PRINTF_SUPPORT_LONG_LONG @PRINTF_SUPPORT_LONG_LONG@
#define PRINTF_ALIAS_STANDARD_FUNCTION_NAMES @PRINTF_ALIAS_STANDARD_FUNCTION_NAMES@
#define PRINTF_USE_DOUBLE_INTERNALLY @PRINTF_USE_DOUBLE_INTERNALLY@

#define PRINTF_INTEGER_BUFFER_SIZE @PRINTF_INTEGER_BUFFER_SIZE@
#define PRINTF_DECIMAL_BUFFER_SIZE @PRINTF_DECIMAL_BUFFER_SIZE@
Expand Down
Loading

0 comments on commit 83f5811

Please sign in to comment.