C
Join ServerC#
help
✅ dumb question involving Math.Max
BBenMcLean1/27/2023
Given that
a
and b
are 32-bit integers within the range of -100 to 100, this should always return True
right?int first = a < b ? 0 : a - b;
int second = Math.Max(a - b, 0);
return first == second;
BBenMcLean1/27/2023
my brain's scrambled and i'm up way too late, that's my problem
BBenMcLean1/27/2023
yeah ... no exception. what the heck
for (int a = -100; a < 100; a++)
for (int b = -100; b < 100; b++)
if ((a < b ? 0 : a - b) != Math.Max(a - b, 0))
throw new Exception();
EEro1/27/2023
why would this throw an exception? you just said yourself that they should always be equal
EEro1/27/2023
so they're never not equal. which is what you're testing for
BBenMcLean1/27/2023
yeah i was getting a result that looked crazy but it turns out i just needed to change an X to a Z in a different place 🙂
BBenMcLean1/27/2023
how i delete this
BBenMcLean1/27/2023
i got it figured out, it wasn't this