1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsExceptionHandlerUtils.h"
11 #include "double-conversion/double-conversion.h"
13 // Format a non-negative double to a string, without using C-library functions,
14 // which need to be avoided (.e.g. bug 1240160, comment 10). Return false if
15 // we failed to get the formatting done correctly.
16 bool SimpleNoCLibDtoA(double aValue
, char* aBuffer
, int aBufferLength
) {
17 // aBufferLength is the size of the buffer. Be paranoid.
18 aBuffer
[aBufferLength
- 1] = '\0';
27 double_conversion::DoubleToStringConverter::DoubleToAscii(
28 aValue
, double_conversion::DoubleToStringConverter::SHORTEST
, 8, aBuffer
,
29 aBufferLength
, &sign
, &length
, &point
);
31 // length does not account for the 0 terminator.
32 if (length
> point
&& (length
+ 1) < (aBufferLength
- 1)) {
33 // We have to insert a decimal point. Not worried about adding a leading
34 // zero in the < 1 (point == 0) case.
35 aBuffer
[length
+ 1] = '\0';
36 for (i
= length
; i
> std::max(point
, 0); i
-= 1) {
37 aBuffer
[i
] = aBuffer
[i
- 1];
39 aBuffer
[i
] = '.'; // Not worried about locales
40 } else if (length
< point
) {
41 // Trailing zeros scenario
42 for (i
= length
; i
< point
; i
+= 1) {
43 if (i
>= aBufferLength
- 2) {