mirror of https://github.com/adamdruppe/arsd.git
long.min is a weird number
This commit is contained in:
parent
469072ee72
commit
f7c2cbc0d2
35
core.d
35
core.d
|
|
@ -818,7 +818,7 @@ struct LimitedVariant {
|
||||||
else
|
else
|
||||||
return isHighBitSet ? Contains.bytes : Contains.string;
|
return isHighBitSet ? Contains.bytes : Contains.string;
|
||||||
} else {
|
} else {
|
||||||
return Contains.invalid;
|
return isHighBitSet ? Contains.bytes : Contains.invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1576,6 +1576,14 @@ char[] intToString(long value, char[] buffer, IntToStringArgs args = IntToString
|
||||||
|
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
|
bool needsOverflowFixup = false;
|
||||||
|
|
||||||
|
if(value == long.min) {
|
||||||
|
// -long.min will overflow so we're gonna cheat
|
||||||
|
value += 1;
|
||||||
|
needsOverflowFixup = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(value < 0) {
|
if(value < 0) {
|
||||||
buffer[pos++] = '-';
|
buffer[pos++] = '-';
|
||||||
value = -value;
|
value = -value;
|
||||||
|
|
@ -1585,18 +1593,33 @@ char[] intToString(long value, char[] buffer, IntToStringArgs args = IntToString
|
||||||
int digitCount;
|
int digitCount;
|
||||||
int groupCount;
|
int groupCount;
|
||||||
|
|
||||||
do {
|
void outputDigit(char c) {
|
||||||
auto remainder = value % radix;
|
|
||||||
value = value / radix;
|
|
||||||
|
|
||||||
if(groupSize && groupCount == groupSize) {
|
if(groupSize && groupCount == groupSize) {
|
||||||
buffer[pos++] = args.separator;
|
buffer[pos++] = args.separator;
|
||||||
groupCount = 0;
|
groupCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer[pos++] = cast(char) (remainder < 10 ? (remainder + '0') : (remainder - 10 + args.ten));
|
buffer[pos++] = c;
|
||||||
groupCount++;
|
groupCount++;
|
||||||
digitCount++;
|
digitCount++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
auto remainder = value % radix;
|
||||||
|
value = value / radix;
|
||||||
|
if(needsOverflowFixup) {
|
||||||
|
if(remainder + 1 == radix) {
|
||||||
|
outputDigit('0');
|
||||||
|
remainder = 0;
|
||||||
|
value += 1;
|
||||||
|
} else {
|
||||||
|
remainder += 1;
|
||||||
|
}
|
||||||
|
needsOverflowFixup = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
outputDigit(cast(char) (remainder < 10 ? (remainder + '0') : (remainder - 10 + args.ten)));
|
||||||
} while(value);
|
} while(value);
|
||||||
|
|
||||||
if(digitsPad > 0) {
|
if(digitsPad > 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue