Skip to content

Commit 408ebfb

Browse files
committed
Fix the SSE path
1 parent 3235751 commit 408ebfb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

zmij.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ static char* write_significand17(char* buffer, uint64_t value, bool has17digits,
11881188
// We always write 17 digits into the buffer, but the first one can be zero.
11891189
// buffer points to the second place in the output buffer to allow for the
11901190
// insertion of the decimal point, so we can use the first place as scratch.
1191-
buffer += has17digits;
1191+
buffer += has17digits - 1;
11921192
buffer[16] = char(last_digit + '0');
11931193

11941194
uint32_t abcdefgh = value_div10 / uint64_t(1e8);
@@ -1636,9 +1636,11 @@ char* zmij_write_double(double value, char* buffer) {
16361636
#endif
16371637

16381638
if (dec_exp >= -4 && dec_exp < 0) {
1639+
char* point = buffer + 1;
16391640
memcpy(buffer, "0.0000000", 8);
16401641
buffer = write_significand17(buffer + 1 - dec_exp, dec.sig, has17digits,
16411642
sig_div10);
1643+
if (ZMIJ_USE_SSE) *point = '.';
16421644
*buffer = '\0';
16431645
return buffer;
16441646
}

zmij.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ auto write_significand17(char* buffer, uint64_t value, bool has17digits,
605605
// We always write 17 digits into the buffer, but the first one can be zero.
606606
// buffer points to the second place in the output buffer to allow for the
607607
// insertion of the decimal point, so we can use the first place as scratch.
608-
buffer += has17digits;
608+
buffer += has17digits - 1;
609609
buffer[16] = char(last_digit + '0');
610610

611611
uint32_t abcdefgh = value_div10 / uint64_t(1e8);
@@ -872,11 +872,13 @@ template <int num_bits>
872872
auto write_fixed(char* buffer, uint64_t dec_sig, int dec_exp, bool extra_digit,
873873
long long dec_sig_div10) noexcept -> char* {
874874
if (dec_exp < 0) {
875+
char* point = buffer + 1;
875876
memcpy(buffer, "0.0000000", 8);
876877
buffer = num_bits == 64 ? write_significand17(buffer + 1 - dec_exp, dec_sig,
877878
extra_digit, dec_sig_div10)
878879
: write_significand9(buffer + 1 - dec_exp, dec_sig,
879880
extra_digit);
881+
if (ZMIJ_USE_SSE) *point = '.';
880882
*buffer = '\0';
881883
return buffer;
882884
}

0 commit comments

Comments
 (0)