Skip to content

Commit 7a60b26

Browse files
committed
Minor improvements
1 parent 523e392 commit 7a60b26

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

zmij.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,16 +1059,17 @@ auto to_decimal(UInt bin_sig, int bin_exp, bool regular,
10591059
uint64_t upper = rem10 + scaled_half_ulp;
10601060

10611061
// An optimization from yy by Yaoyuan Guo:
1062+
int64_t cmp = int64_t(fractional - (uint64_t(1) << 63));
10621063
if (
10631064
// Exact half-ulp tie when rounding to nearest integer.
1064-
fractional != (uint64_t(1) << 63) &&
1065+
cmp != 0 &&
10651066
// Exact half-ulp tie when rounding to nearest 10.
10661067
rem10 != scaled_half_ulp &&
10671068
// Near-boundary case for rounding to nearest 10.
10681069
ten - upper > uint64_t(1)) [[ZMIJ_LIKELY]] {
10691070
bool round_up = (upper >> num_fractional_bits) >= 10;
10701071
uint64_t shorter = integral - digit + round_up * 10;
1071-
uint64_t longer = integral + (fractional >= (uint64_t(1) << 63));
1072+
uint64_t longer = integral + (cmp >= 0);
10721073
return {((rem10 <= scaled_half_ulp) + round_up != 0) ? shorter : longer,
10731074
dec_exp};
10741075
}
@@ -1183,9 +1184,8 @@ auto write(Float value, char* buffer) noexcept -> char* {
11831184
*buffer = char('0' + a);
11841185
buffer += dec_exp >= 100;
11851186
memcpy(buffer, digits2(bb), 2);
1186-
buffer += 2;
1187-
*buffer = '\0';
1188-
return buffer;
1187+
buffer[2] = '\0';
1188+
return buffer + 2;
11891189
}
11901190

11911191
template auto write(double value, char* buffer) noexcept -> char*;

0 commit comments

Comments
 (0)