summaryrefslogtreecommitdiffstats
path: root/js/src/util/DoubleToString.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/util/DoubleToString.h
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/util/DoubleToString.h')
-rw-r--r--js/src/util/DoubleToString.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/js/src/util/DoubleToString.h b/js/src/util/DoubleToString.h
new file mode 100644
index 0000000000..3877a062b7
--- /dev/null
+++ b/js/src/util/DoubleToString.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set ts=8 sts=2 et sw=2 tw=80:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef util_DoubleToString_h
+#define util_DoubleToString_h
+
+/*
+ * Public interface to portable double-precision floating point to string
+ * and back conversion package.
+ */
+
+struct DtoaState;
+
+namespace js {
+
+extern DtoaState* NewDtoaState();
+
+extern void DestroyDtoaState(DtoaState* state);
+
+} // namespace js
+
+/* Maximum number of characters (including trailing null) that a DTOSTR_STANDARD
+ * or DTOSTR_STANDARD_EXPONENTIAL conversion can produce. This maximum is
+ * reached for a number like -0.0000012345678901234567. */
+#define DTOSTR_STANDARD_BUFFER_SIZE 26
+
+/*
+ * DO NOT USE THIS FUNCTION IF YOU CAN AVOID IT. js::NumberToCString() is a
+ * better function to use.
+ *
+ * Convert d to a string in the given base. The integral part of d will be
+ * printed exactly in that base, regardless of how large it is, because there
+ * is no exponential notation for non-base-ten numbers. The fractional part
+ * will be rounded to as few digits as possible while still preserving the
+ * round-trip property (analogous to that of printing decimal numbers). In
+ * other words, if one were to read the resulting string in via a hypothetical
+ * base-number-reading routine that rounds to the nearest IEEE double (and to
+ * an even significand if there are two equally near doubles), then the result
+ * would equal d (except for -0.0, which converts to "0", and NaN, which is
+ * not equal to itself).
+ *
+ * Return nullptr if out of memory. If the result is not nullptr, it must be
+ * released via js_free().
+ */
+char* js_dtobasestr(DtoaState* state, int base, double d);
+
+#endif /* util_DoubleToString_h */