[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Found an issue when compiling raylib with TCC

From: Michael Matz
Subject: Re: [Tinycc-devel] Found an issue when compiling raylib with TCC
Date: Thu, 31 May 2018 22:42:58 +0200 (CEST)
User-agent: Alpine 2.20 (LSU 67 2015-01-07)


On Mon, 28 May 2018, Ray wrote:

Just found an issue when compiling with TCC, it seems that TCC is not
casting some int values correctly to float when dividing, I mean:

Which version of TCC?  (mob branch or anything else?)

Following code fails on calculating correct float coordinates:

// sourceRec.x, sourceRec.y are floats
// texture.width, texture.height are int
rlTexCoord2f(sourceRec.x/texture.width, sourceRec.y/texture.height);

Same code works perfectly with MinGW, GCC, MSVC, Clang...

Also tried: 


Instead I had to do:

float width = (float)texture.width;
float height = (float)texture.height;

rlTexCoord2f(sourceRec.x/width, sourceRec.y/height);

More info about this issue: https://github.com/raysan5/raylib/issues/553

I can't find a test which reproduces a problem with current mob branch. I tried:

% cat x.c
#include <stdio.h>

void get2f (float a, float b)
  printf("%f %f\n", a, b);

struct F2 {
    float x,y;
struct I2 {
    int width, height;

int main()
  struct F2 a = {5.5f, 42.3f};
  struct I2 b = {1024, 768};
  get2f(a.x/(float)b.width, a.y/(float)b.height);
  return 0;
% tcc x.c && ./a.out
0.005371 0.055078

(which is the correct result) It also works without the explicit casts to float in the divisions, and it works when the initialization of a and b are done via assignments, not in the initializer. So I fear you'll have to get us a self-contained testcase showing a problem (or confirm that it's no problem anymore with mob branch).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]