aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-05-06 17:27:07 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-05-06 17:27:07 -0400
commitdb7ca4715d6fb56a492839b14525a8e18d46de45 (patch)
tree74523438fccdc625fd43ebae5a7c01f4bf2427bb /src
parent2dfaa75c1b711aa26339367bf5bfbb4ac17a8709 (diff)
Bugfix for truncation of Bytes
Diffstat (limited to 'src')
-rw-r--r--src/stdlib/bytes.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/stdlib/bytes.c b/src/stdlib/bytes.c
index 3373cb55..b5c10aa2 100644
--- a/src/stdlib/bytes.c
+++ b/src/stdlib/bytes.c
@@ -79,24 +79,24 @@ public CONSTFUNC Closure_t Byte$to(Byte_t first, Byte_t last, OptionalInt8_t ste
}
public PUREFUNC Byte_t Byte$from_int(Int_t i, bool truncate) {
- if unlikely (truncate && Int$compare_value(i, I_small(0xFF)) > 0)
+ if unlikely (!truncate && Int$compare_value(i, I_small(0xFF)) > 0)
fail("This value is too large to convert to a byte without truncation: ", i);
- else if unlikely (truncate && Int$compare_value(i, I_small(0)) < 0)
+ else if unlikely (!truncate && Int$compare_value(i, I_small(0)) < 0)
fail("Negative values can't be converted to bytes: ", i);
return (Byte_t)(i.small >> 2);
}
public PUREFUNC Byte_t Byte$from_int64(Int64_t i, bool truncate) {
- if unlikely (truncate && i != (Int64_t)(Byte_t)i)
+ if unlikely (!truncate && i != (Int64_t)(Byte_t)i)
fail("This value can't be converted to a byte without truncation: ", i);
return (Byte_t)i;
}
public PUREFUNC Byte_t Byte$from_int32(Int32_t i, bool truncate) {
- if unlikely (truncate && i != (Int32_t)(Byte_t)i)
+ if unlikely (!truncate && i != (Int32_t)(Byte_t)i)
fail("This value can't be converted to a byte without truncation: ", i);
return (Byte_t)i;
}
public PUREFUNC Byte_t Byte$from_int16(Int16_t i, bool truncate) {
- if unlikely (truncate && i != (Int16_t)(Byte_t)i)
+ if unlikely (!truncate && i != (Int16_t)(Byte_t)i)
fail("This value can't be converted to a byte without truncation: ", i);
return (Byte_t)i;
}