Skip to content

Commit 0460c81

Browse files
committed
ENH: Update Double-convert third-party
Fix typos in comments CMakeLists.txt: Export all symbols (InsightSoftwareConsortium#136) test/cctest/CMakeLists.txt: Added /bigobj for MSVC tests (InsightSoftwareConsortium#135) Add DOUBLE_CONVERSION_HAS_ATTRIBUTE to fix warnings on MSVC and enable for GCC. (InsightSoftwareConsortium#131) Fix broken MSVC builds. (InsightSoftwareConsortium#130) Add support for quiet and signaling NaNs to the ieee header. (InsightSoftwareConsortium#128) Move buffer and buffer_pos down (InsightSoftwareConsortium#125) * Move buffer and buffer_pos down Simplifies code by removing two asserts Optimize code with -ftrivial-auto-var-init=pattern by avoiding initialization when buffer is not used * Disable -ftrivial-auto-var-init=pattern for a large buffer Fix strtod.cc undefined constants (InsightSoftwareConsortium#123) When DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS is not defined there is a build error when -Wall -Werror enabled because kMaxExactDoubleIntegerDecimalDigits, exact_powers_of_ten and kExactPowersOfTenSize are used only in else branch of this define (when it's defined). Fixes google/double-conversion#122 Add full license to test .cc files missing it. (InsightSoftwareConsortium#121) Some files in cctest had a 1-line copyright that doesn't list the license. This copies the project license to those files, preserving the date. Add wasm32 as supported platform (InsightSoftwareConsortium#120) Summary: Emscripten is already included, adding wasm32 the same way for when build with "plain" clang wasm32 (without emscripten) Pseiderer/add nios2 and xtensa 001 (InsightSoftwareConsortium#119) * double-conversion: enable for nios2 Nios2 supports double conversion, tested using qemu: Add support for microblaze. Add support for e2k architecture. (InsightSoftwareConsortium#118) Add min exponent width option in double-to-string conversion (InsightSoftwareConsortium#116) Remove reference to `diy-fp.cc` That file was removed in a previous commit. More Bignum fiddling. (InsightSoftwareConsortium#108) * Char has size 1. * More const. * Allow inlining. * Compact Bignum sizes. * Consistent naming. Remove redundant parenthesis. Reported by seanm (github). Optimise Bignum layout. (InsightSoftwareConsortium#107) * Use memset to clear bignum. * Improve data locality. * Reduce size of bignum. Split Strtod() (InsightSoftwareConsortium#106) Add `StrtodTrimmed` method, exposing a later stage of the conversion pipeline. Some tools can do the first stage outside of the double-conversion library and would prefer not to pay the cost of doing it again. Split double-conversion. (InsightSoftwareConsortium#104) Separates the two main classes into separate c and h files. Fix naming. (InsightSoftwareConsortium#103) Fix naming of `case_insensibility` to `case_insensitivity`. Consistent macro prefix. (InsightSoftwareConsortium#101) Use standard min/max. (InsightSoftwareConsortium#102) Fix some issues with invalid hex-float literals. When converting `0x` the converter would assert (or access out of boundary). With `0x1.p1234556666FFFFF` the converter would overflow and not yield the correct exponent. Usefulcat master (InsightSoftwareConsortium#98) * minor bug fix: use free() instead of delete[] to free memory allocated by strdup() * fix for uninitialized variable problem found by valgrind * disable assertions for 'optimize' build * removed -g option that was inadvertently added to CCFLAGS * ignore generated files Fix warning for g++ 4.9.3. CMake: install to correct lib dir (InsightSoftwareConsortium#93) 64-bit libraries should be installed in /usr/lib64, not in /usr/lib/ Make the destination lib dir configurable. Add big endian ARM support (InsightSoftwareConsortium#92) This fixes compilation on such platforms. Switch to relative includes. Fix 16-bit separators. msvc: check if _MSC_VER is defined (InsightSoftwareConsortium#88) Allow for compilation in emscripten (InsightSoftwareConsortium#86) Support emscripten Add test cases. Fixes InsightSoftwareConsortium#62 Add support of ARC architecture (InsightSoftwareConsortium#82) More info about ARC architecture is here: [1] & [2]. We need ARC supported here for many things like: - ICU (see [3]) - Qt5 etc Fix hex literal bug. Large hex literals would lose their minus sign. Support separator characters. Add support for hexadecimal float literals. Fix bug where hex numbers would lose the minus sign. Add comments for achitecture check. This should make it easier to add new architectures. Add support for aarch64_be, or1k and microblazebe. Add support for Windows on ARM and ARM64 (InsightSoftwareConsortium#76) Use `static_assert` with newer compilers. Add Native Client as support architecture. Avoid undefined cast to make ASAN happy. Avoid undefined cast to make ASAN happy. Add `exports_files` Processed length should include no trailing junk (InsightSoftwareConsortium#63) Clarify output charset in DoubleToAscii documentation (InsightSoftwareConsortium#61) * Clarify output charset in DoubleToAscii documentation * Fixing typo in charset docs. Fix warning for code that will never be executed (InsightSoftwareConsortium#59) Rename macros. Renamed DISALLOW_COPY_AND_ASSIGN and DISALLOW_IMPLICIT_CONSTRUCTORS to DC_DISALLOW_COPY_AND_ASSIGN and DC_DISALLOW_IMPLICIT_CONSTRUCTORS. This makes it easier to use this library in projects that have macros with the same name (as is common in Google). Some refactorings: remove unused static, replace deprecated headers, init member in constructor REF: replace deprecated headers REF: meaningless static definition in anonymous namespace REF: init member in constructor Fix typo in variable name. Suppress issue in clang analyzer. CMake fixes. Remove unused CMake file. Implement ALLOW_CASE_INSENSIBILITY mode for StringToDoubleConverter c… Remove unnecessary INSTALL_INTERFACE expression. Use template for CMake installation. Fix mistake for build interface include dir. Improve CMake changes. Update CMake package generation. Implement ALLOW_CASE_INSENSIBILITY mode for StringToDoubleConverter class Add assert and test. Avoid negative shift. When filling in fractional digits in a fixed representation we might use all existing digits. When this happens, we can not look at the next digit to see if we should round up. Before this fix, we tried to shift by a negative amount to see if the (non-existing) next bit was set to 1 (requiring the number to be rounded up).
1 parent 22b5543 commit 0460c81

File tree

20 files changed

+2088
-1660
lines changed

20 files changed

+2088
-1660
lines changed

Modules/ThirdParty/DoubleConversion/src/double-conversion/CMakeLists.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,32 @@ configure_file(double-conversion-configure.h.in double-conversion-configure.h)
2222
include_directories(${CMAKE_CURRENT_BINARY_DIR})
2323

2424
set(headers
25+
bignum-dtoa.h
2526
bignum.h
2627
cached-powers.h
2728
diy-fp.h
2829
double-conversion.h
30+
double-to-string.h
2931
fast-dtoa.h
3032
fixed-dtoa.h
3133
ieee.h
34+
string-to-double.h
3235
strtod.h
3336
utils.h
3437
${CMAKE_CURRENT_BINARY_DIR}/double-conversion-configure.h
35-
)
38+
)
39+
3640

3741
add_library(itkdouble-conversion
38-
bignum.cc
39-
bignum-dtoa.cc
40-
cached-powers.cc
41-
diy-fp.cc
42-
double-conversion.cc
43-
fast-dtoa.cc
44-
fixed-dtoa.cc
45-
strtod.cc
46-
${headers}
42+
bignum.cc
43+
bignum-dtoa.cc
44+
cached-powers.cc
45+
double-to-string.cc
46+
fast-dtoa.cc
47+
fixed-dtoa.cc
48+
string-to-double.cc
49+
strtod.cc
50+
${headers}
4751
)
4852

4953
if(ITK_LIBRARY_PROPERTIES)

Modules/ThirdParty/DoubleConversion/src/double-conversion/SConscript

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ double_conversion_sources = [
33
'bignum.cc',
44
'bignum-dtoa.cc',
55
'cached-powers.cc',
6-
'diy-fp.cc',
7-
'double-conversion.cc',
6+
'double-to-string.cc',
87
'fast-dtoa.cc',
98
'fixed-dtoa.cc',
9+
'string-to-double.cc',
1010
'strtod.cc'
1111
]
1212
Return('double_conversion_sources')

Modules/ThirdParty/DoubleConversion/src/double-conversion/bignum-dtoa.cc

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2626
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727

28-
#include <math.h>
28+
#include <cmath>
2929

3030
#include "bignum-dtoa.h"
3131

@@ -35,7 +35,7 @@
3535
namespace double_conversion {
3636

3737
static int NormalizedExponent(uint64_t significand, int exponent) {
38-
ASSERT(significand != 0);
38+
DOUBLE_CONVERSION_ASSERT(significand != 0);
3939
while ((significand & Double::kHiddenBit) == 0) {
4040
significand = significand << 1;
4141
exponent = exponent - 1;
@@ -76,26 +76,26 @@ static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
7676
// Generates 'requested_digits' after the decimal point.
7777
static void BignumToFixed(int requested_digits, int* decimal_point,
7878
Bignum* numerator, Bignum* denominator,
79-
Vector<char>(buffer), int* length);
79+
Vector<char> buffer, int* length);
8080
// Generates 'count' digits of numerator/denominator.
8181
// Once 'count' digits have been produced rounds the result depending on the
8282
// remainder (remainders of exactly .5 round upwards). Might update the
8383
// decimal_point when rounding up (for example for 0.9999).
8484
static void GenerateCountedDigits(int count, int* decimal_point,
8585
Bignum* numerator, Bignum* denominator,
86-
Vector<char>(buffer), int* length);
86+
Vector<char> buffer, int* length);
8787

8888

8989
void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits,
9090
Vector<char> buffer, int* length, int* decimal_point) {
91-
ASSERT(v > 0);
92-
ASSERT(!Double(v).IsSpecial());
91+
DOUBLE_CONVERSION_ASSERT(v > 0);
92+
DOUBLE_CONVERSION_ASSERT(!Double(v).IsSpecial());
9393
uint64_t significand;
9494
int exponent;
9595
bool lower_boundary_is_closer;
9696
if (mode == BIGNUM_DTOA_SHORTEST_SINGLE) {
9797
float f = static_cast<float>(v);
98-
ASSERT(f == v);
98+
DOUBLE_CONVERSION_ASSERT(f == v);
9999
significand = Single(f).Significand();
100100
exponent = Single(f).Exponent();
101101
lower_boundary_is_closer = Single(f).LowerBoundaryIsCloser();
@@ -134,7 +134,7 @@ void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits,
134134
// 4e-324. In this case the denominator needs fewer than 324*4 binary digits.
135135
// The maximum double is 1.7976931348623157e308 which needs fewer than
136136
// 308*4 binary digits.
137-
ASSERT(Bignum::kMaxSignificantBits >= 324*4);
137+
DOUBLE_CONVERSION_ASSERT(Bignum::kMaxSignificantBits >= 324*4);
138138
InitialScaledStartValues(significand, exponent, lower_boundary_is_closer,
139139
estimated_power, need_boundary_deltas,
140140
&numerator, &denominator,
@@ -163,7 +163,7 @@ void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits,
163163
buffer, length);
164164
break;
165165
default:
166-
UNREACHABLE();
166+
DOUBLE_CONVERSION_UNREACHABLE();
167167
}
168168
buffer[*length] = '\0';
169169
}
@@ -195,7 +195,7 @@ static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
195195
for (;;) {
196196
uint16_t digit;
197197
digit = numerator->DivideModuloIntBignum(*denominator);
198-
ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive.
198+
DOUBLE_CONVERSION_ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive.
199199
// digit = numerator / denominator (integer division).
200200
// numerator = numerator % denominator.
201201
buffer[(*length)++] = static_cast<char>(digit + '0');
@@ -241,7 +241,7 @@ static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
241241
// loop would have stopped earlier.
242242
// We still have an assert here in case the preconditions were not
243243
// satisfied.
244-
ASSERT(buffer[(*length) - 1] != '9');
244+
DOUBLE_CONVERSION_ASSERT(buffer[(*length) - 1] != '9');
245245
buffer[(*length) - 1]++;
246246
} else {
247247
// Halfway case.
@@ -252,7 +252,7 @@ static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
252252
if ((buffer[(*length) - 1] - '0') % 2 == 0) {
253253
// Round down => Do nothing.
254254
} else {
255-
ASSERT(buffer[(*length) - 1] != '9');
255+
DOUBLE_CONVERSION_ASSERT(buffer[(*length) - 1] != '9');
256256
buffer[(*length) - 1]++;
257257
}
258258
}
@@ -264,9 +264,9 @@ static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
264264
// Round up.
265265
// Note again that the last digit could not be '9' since this would have
266266
// stopped the loop earlier.
267-
// We still have an ASSERT here, in case the preconditions were not
267+
// We still have an DOUBLE_CONVERSION_ASSERT here, in case the preconditions were not
268268
// satisfied.
269-
ASSERT(buffer[(*length) -1] != '9');
269+
DOUBLE_CONVERSION_ASSERT(buffer[(*length) -1] != '9');
270270
buffer[(*length) - 1]++;
271271
return;
272272
}
@@ -283,11 +283,11 @@ static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
283283
static void GenerateCountedDigits(int count, int* decimal_point,
284284
Bignum* numerator, Bignum* denominator,
285285
Vector<char> buffer, int* length) {
286-
ASSERT(count >= 0);
286+
DOUBLE_CONVERSION_ASSERT(count >= 0);
287287
for (int i = 0; i < count - 1; ++i) {
288288
uint16_t digit;
289289
digit = numerator->DivideModuloIntBignum(*denominator);
290-
ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive.
290+
DOUBLE_CONVERSION_ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive.
291291
// digit = numerator / denominator (integer division).
292292
// numerator = numerator % denominator.
293293
buffer[i] = static_cast<char>(digit + '0');
@@ -300,7 +300,7 @@ static void GenerateCountedDigits(int count, int* decimal_point,
300300
if (Bignum::PlusCompare(*numerator, *numerator, *denominator) >= 0) {
301301
digit++;
302302
}
303-
ASSERT(digit <= 10);
303+
DOUBLE_CONVERSION_ASSERT(digit <= 10);
304304
buffer[count - 1] = static_cast<char>(digit + '0');
305305
// Correct bad digits (in case we had a sequence of '9's). Propagate the
306306
// carry until we hat a non-'9' or til we reach the first digit.
@@ -325,7 +325,7 @@ static void GenerateCountedDigits(int count, int* decimal_point,
325325
// Input verifies: 1 <= (numerator + delta) / denominator < 10.
326326
static void BignumToFixed(int requested_digits, int* decimal_point,
327327
Bignum* numerator, Bignum* denominator,
328-
Vector<char>(buffer), int* length) {
328+
Vector<char> buffer, int* length) {
329329
// Note that we have to look at more than just the requested_digits, since
330330
// a number could be rounded up. Example: v=0.5 with requested_digits=0.
331331
// Even though the power of v equals 0 we can't just stop here.
@@ -341,7 +341,7 @@ static void BignumToFixed(int requested_digits, int* decimal_point,
341341
} else if (-(*decimal_point) == requested_digits) {
342342
// We only need to verify if the number rounds down or up.
343343
// Ex: 0.04 and 0.06 with requested_digits == 1.
344-
ASSERT(*decimal_point == -requested_digits);
344+
DOUBLE_CONVERSION_ASSERT(*decimal_point == -requested_digits);
345345
// Initially the fraction lies in range (1, 10]. Multiply the denominator
346346
// by 10 so that we can compare more easily.
347347
denominator->Times10();
@@ -370,7 +370,7 @@ static void BignumToFixed(int requested_digits, int* decimal_point,
370370
// Returns an estimation of k such that 10^(k-1) <= v < 10^k where
371371
// v = f * 2^exponent and 2^52 <= f < 2^53.
372372
// v is hence a normalized double with the given exponent. The output is an
373-
// approximation for the exponent of the decimal approimation .digits * 10^k.
373+
// approximation for the exponent of the decimal approximation .digits * 10^k.
374374
//
375375
// The result might undershoot by 1 in which case 10^k <= v < 10^k+1.
376376
// Note: this property holds for v's upper boundary m+ too.
@@ -420,7 +420,7 @@ static void InitialScaledStartValuesPositiveExponent(
420420
Bignum* numerator, Bignum* denominator,
421421
Bignum* delta_minus, Bignum* delta_plus) {
422422
// A positive exponent implies a positive power.
423-
ASSERT(estimated_power >= 0);
423+
DOUBLE_CONVERSION_ASSERT(estimated_power >= 0);
424424
// Since the estimated_power is positive we simply multiply the denominator
425425
// by 10^estimated_power.
426426

@@ -506,7 +506,7 @@ static void InitialScaledStartValuesNegativeExponentNegativePower(
506506
// numerator = v * 10^-estimated_power * 2 * 2^-exponent.
507507
// Remember: numerator has been abused as power_ten. So no need to assign it
508508
// to itself.
509-
ASSERT(numerator == power_ten);
509+
DOUBLE_CONVERSION_ASSERT(numerator == power_ten);
510510
numerator->MultiplyByUInt64(significand);
511511

512512
// denominator = 2 * 2^-exponent with exponent < 0.
@@ -548,7 +548,7 @@ static void InitialScaledStartValuesNegativeExponentNegativePower(
548548
//
549549
// Let ep == estimated_power, then the returned values will satisfy:
550550
// v / 10^ep = numerator / denominator.
551-
// v's boundarys m- and m+:
551+
// v's boundaries m- and m+:
552552
// m- / 10^ep == v / 10^ep - delta_minus / denominator
553553
// m+ / 10^ep == v / 10^ep + delta_plus / denominator
554554
// Or in other words:

0 commit comments

Comments
 (0)