CE-Programming / toolchain

Toolchain and libraries for C/C++ programming on the TI-84+ CE calculator series
https://ce-programming.github.io/toolchain/index.html
GNU Lesser General Public License v3.0
527 stars 53 forks source link

`__ultof` actually implements `__ltof` #466

Open runer112 opened 11 months ago

runer112 commented 11 months ago

And __ltof implements a worse __ltof.

Example code demonstrating issue:

#include <ti/getcsc.h>
#include <ti/screen.h>

#include <limits.h>
#include <stdio.h>

void testl(long x) {
  printf("%11li -> %11.0f", x, (float)x);
}

void testul(unsigned long x) {
  printf("%11lu -> %11.0f", x, (float)x);
}

int main() {
  os_ClrHome();

  testl(LONG_MAX);
  testl(LONG_MIN);
  testl(ULONG_MAX);
  os_NewLine();
  testul(LONG_MAX);
  testul(LONG_MIN);
  testul(ULONG_MAX);

  while (!os_GetCSC())
    ;
}

image

runer112 commented 11 months ago

__ultof and __ltof are both implemented as if __fppack accepts an unsigned 32-bit integer input, but it actually expects a signed 32-bit integer input.

runer112 commented 11 months ago

Discovered by 418cat: https://discord.com/channels/432891584451706892/432891584875593730/1188975936603947069.