PageRenderTime 2279ms CodeModel.GetById 2267ms RepoModel.GetById 1ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/js/jsdtoa.h

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
C++ Header | 131 lines | 25 code | 13 blank | 93 comment | 0 complexity | 91637588bad6c2ea79b704efaa026a26 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * ***** BEGIN LICENSE BLOCK *****
  4. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. *
  6. * The contents of this file are subject to the Mozilla Public License Version
  7. * 1.1 (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. * http://www.mozilla.org/MPL/
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is Mozilla Communicator client code, released
  17. * March 31, 1998.
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Netscape Communications Corporation.
  21. * Portions created by the Initial Developer are Copyright (C) 1998
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either of the GNU General Public License Version 2 or later (the "GPL"),
  28. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. #ifndef jsdtoa_h___
  40. #define jsdtoa_h___
  41. /*
  42. * Public interface to portable double-precision floating point to string
  43. * and back conversion package.
  44. */
  45. #include "jscompat.h"
  46. JS_BEGIN_EXTERN_C
  47. /*
  48. * JS_strtod() returns as a double-precision floating-point number
  49. * the value represented by the character string pointed to by
  50. * s00. The string is scanned up to the first unrecognized
  51. * character.
  52. * If the value of se is not (char **)NULL, a pointer to
  53. * the character terminating the scan is returned in the location pointed
  54. * to by se. If no number can be formed, se is set to s00r, and
  55. * zero is returned.
  56. *
  57. * *err is set to zero on success; it's set to JS_DTOA_ERANGE on range
  58. * errors and JS_DTOA_ENOMEM on memory failure.
  59. */
  60. #define JS_DTOA_ERANGE 1
  61. #define JS_DTOA_ENOMEM 2
  62. JS_FRIEND_API(double)
  63. JS_strtod(const char *s00, char **se, int *err);
  64. /*
  65. * Modes for converting floating-point numbers to strings.
  66. *
  67. * Some of the modes can round-trip; this means that if the number is converted to
  68. * a string using one of these mode and then converted back to a number, the result
  69. * will be identical to the original number (except that, due to ECMA, -0 will get converted
  70. * to +0). These round-trip modes return the minimum number of significand digits that
  71. * permit the round trip.
  72. *
  73. * Some of the modes take an integer parameter <precision>.
  74. */
  75. /* NB: Keep this in sync with number_constants[]. */
  76. typedef enum JSDToStrMode {
  77. DTOSTR_STANDARD, /* Either fixed or exponential format; round-trip */
  78. DTOSTR_STANDARD_EXPONENTIAL, /* Always exponential format; round-trip */
  79. DTOSTR_FIXED, /* Round to <precision> digits after the decimal point; exponential if number is large */
  80. DTOSTR_EXPONENTIAL, /* Always exponential format; <precision> significant digits */
  81. DTOSTR_PRECISION /* Either fixed or exponential format; <precision> significant digits */
  82. } JSDToStrMode;
  83. /* Maximum number of characters (including trailing null) that a DTOSTR_STANDARD or DTOSTR_STANDARD_EXPONENTIAL
  84. * conversion can produce. This maximum is reached for a number like -0.0000012345678901234567. */
  85. #define DTOSTR_STANDARD_BUFFER_SIZE 26
  86. /* Maximum number of characters (including trailing null) that one of the other conversions
  87. * can produce. This maximum is reached for TO_FIXED, which can generate up to 21 digits before the decimal point. */
  88. #define DTOSTR_VARIABLE_BUFFER_SIZE(precision) ((precision)+24 > DTOSTR_STANDARD_BUFFER_SIZE ? (precision)+24 : DTOSTR_STANDARD_BUFFER_SIZE)
  89. /*
  90. * Convert dval according to the given mode and return a pointer to the resulting ASCII string.
  91. * The result is held somewhere in buffer, but not necessarily at the beginning. The size of
  92. * buffer is given in bufferSize, and must be at least as large as given by the above macros.
  93. *
  94. * Return NULL if out of memory.
  95. */
  96. JS_FRIEND_API(char *)
  97. JS_dtostr(char *buffer, size_t bufferSize, JSDToStrMode mode, int precision, double dval);
  98. /*
  99. * Convert d to a string in the given base. The integral part of d will be printed exactly
  100. * in that base, regardless of how large it is, because there is no exponential notation for non-base-ten
  101. * numbers. The fractional part will be rounded to as few digits as possible while still preserving
  102. * the round-trip property (analogous to that of printing decimal numbers). In other words, if one were
  103. * to read the resulting string in via a hypothetical base-number-reading routine that rounds to the nearest
  104. * IEEE double (and to an even significand if there are two equally near doubles), then the result would
  105. * equal d (except for -0.0, which converts to "0", and NaN, which is not equal to itself).
  106. *
  107. * Return NULL if out of memory. If the result is not NULL, it must be released via free().
  108. */
  109. JS_FRIEND_API(char *)
  110. JS_dtobasestr(int base, double d);
  111. /*
  112. * Clean up any persistent RAM allocated during the execution of DtoA
  113. * routines, and remove any locks that might have been created.
  114. */
  115. JS_FRIEND_API(JSBool) js_InitDtoa(void);
  116. JS_FRIEND_API(void) js_FinishDtoa(void);
  117. JS_END_EXTERN_C
  118. #endif /* jsdtoa_h___ */