|
| 1 | +--- grisu3.h |
| 2 | ++++ grisu3.h |
| 3 | +@@ -1,3 +1,14 @@ |
| 4 | ++/* Copyright Jukka Jylänki |
| 5 | ++ Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ++ you may not use this file except in compliance with the License. |
| 7 | ++ You may obtain a copy of the License at |
| 8 | ++ http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ++ Unless required by applicable law or agreed to in writing, software |
| 10 | ++ distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | ++ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | ++ See the License for the specific language governing permissions and |
| 13 | ++ limitations under the License. */ |
| 14 | ++ |
| 15 | + /* This file is part of an implementation of the "grisu3" double to string |
| 16 | + conversion algorithm described in the research paper |
| 17 | + |
| 18 | +@@ -6,18 +17,9 @@ |
| 19 | + http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf */ |
| 20 | + #pragma once |
| 21 | + |
| 22 | +-#include "../MathBuildConfig.h" |
| 23 | ++extern "C" |
| 24 | ++{ |
| 25 | + |
| 26 | +-#include <stdint.h> |
| 27 | +- |
| 28 | +-#ifdef __cplusplus |
| 29 | +-extern "C" { |
| 30 | +-#endif |
| 31 | +- |
| 32 | +-#ifdef __EMSCRIPTEN__ |
| 33 | +-int js_double_to_string(double d, char *dst); |
| 34 | +-#endif |
| 35 | +- |
| 36 | + /// Converts the given double-precision floating point number to a string representation. |
| 37 | + /** For most inputs, this string representation is the |
| 38 | + shortest such, which deserialized again, returns the same bit |
| 39 | +@@ -30,50 +32,12 @@ |
| 40 | + @return the number of characters written to dst, excluding the null terminator (which |
| 41 | + is always written) is returned here. */ |
| 42 | + int dtoa_grisu3(double v, char *dst); |
| 43 | +-#define f64_to_string dtoa_grisu3 |
| 44 | + |
| 45 | +-int f32_to_string(float v, char *dst); |
| 46 | +- |
| 47 | +-/// Converts an unsigned 32-bit integer to a string. Longest 32-bit unsigned integer is |
| 48 | +-/// 4294967295, which is 10 bytes (11 if including \0) |
| 49 | +-/** @param val The number to convert. |
| 50 | +- @param dst [out] The unsigned number will be written here |
| 51 | +- as a null-terminated string. The conversion algorithm will write at most 11 bytes |
| 52 | +- to this buffer. (null terminator is included in this count). |
| 53 | +- The dst pointer may not be null. |
| 54 | +- @return the number of characters written to dst, excluding the null terminator (which |
| 55 | +- is always written) is returned here. */ |
| 56 | +-int u32_to_string(uint32_t val, char *dst); |
| 57 | +- |
| 58 | +-/// Similar to u32_to_string(), but prints the number in hexadecimal, inluding leading "0x". |
| 59 | +-int u32_to_hex_string(uint32_t val, char *str); |
| 60 | +- |
| 61 | +-/// Converts an signed 32-bit integer to a string. Longest 32-bit signed integer is |
| 62 | +-/// -2147483648, which is 11 bytes (12 if including \0) |
| 63 | +-/** @param val The number to convert. |
| 64 | +- @param dst [out] The unsigned number will be written here |
| 65 | +- as a null-terminated string. The conversion algorithm will write at most 12 bytes |
| 66 | +- to this buffer. (null terminator is included in this count). |
| 67 | +- The dst pointer may not be null. |
| 68 | +- @return the number of characters written to dst, excluding the null terminator (which |
| 69 | +- is always written) is returned here. */ |
| 70 | +-int i32_to_string(int i, char *dst); |
| 71 | +- |
| 72 | +-/// Similar to i32_to_string(), but prints the number in signed hexadecimal, inluding leading "0x". |
| 73 | +-int i32_to_hex_string(int i, char *str); |
| 74 | +- |
| 75 | +-#ifdef __cplusplus |
| 76 | + } |
| 77 | +-#endif |
| 78 | + |
| 79 | + #ifdef __cplusplus |
| 80 | + |
| 81 | +-#if defined(MATH_ENABLE_STL_SUPPORT) |
| 82 | + #include <string> |
| 83 | +-#endif |
| 84 | ++std::string dtoa_grisu3_string(double v); |
| 85 | + |
| 86 | +-#if defined(MATH_ENABLE_STL_SUPPORT) || defined(MATH_CONTAINERLIB_SUPPORT) |
| 87 | +-StringT dtoa_grisu3_string(double v); |
| 88 | + #endif |
| 89 | +- |
| 90 | +-#endif |
0 commit comments