Skip to content
Myr

Merge branch 'upstream' of https://github.com/yangfl/stb into work2

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parents ecf2a56, 5db48d3 · Browse files · 1 file+14 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−6 removed

  • other:+14 added−6 removed

1 file+14 added−6 removed

modified:stb_divide.h+14 added-6 removed
273 unmodified lines
274#include <math.h>275#include <limits.h>276277int show=0;278int err=0;279280void stbdiv_check(int q, int r, int a, int b, char *type, int dir)281{281 if ((dir > 0 && r < 0) || (dir < 0 && r > 0))282 if ((dir > 0 && r < 0) || (dir < 0 && r > 0)) {283 fprintf(stderr, "FAILED: %s(%d,%d) remainder %d in wrong direction\n", type,a,b,r);284 err++;283 else285 } else286 if (b != INT_MIN) // can't compute abs(), but if b==INT_MIN all remainders are valid285 if (r <= -abs(b) || r >= abs(b))287 if (r <= -abs(b) || r >= abs(b)) {288 fprintf(stderr, "FAILED: %s(%d,%d) remainder %d out of range\n", type,a,b,r);289 err++;290 }291 #ifdef STB_DIVIDE_TEST_64292 {293 STB_DIVIDE_TEST_64 q64 = q, r64=r, a64=a, b64=b;290 if (q64*b64+r64 != a64)294 if (q64*b64+r64 != a64) {295 fprintf(stderr, "FAILED: %s(%d,%d) remainder %d doesn't match quotient %d\n", type,a,b,r,q);296 err++;297 }298 }299 #else294 if (q*b+r != a)300 if (q*b+r != a) {301 fprintf(stderr, "FAILED: %s(%d,%d) remainder %d doesn't match quotient %d\n", type,a,b,r,q);302 err++;303 }304 #endif305}306307void test(int a, int b)
71 unmodified lines
379 testh(INT_MAX , INT_MAX);380 testh(INT_MIN , INT_MAX);381 testh(INT_MIN+1, INT_MAX);382375 return 0;383 return err > 0 ? 1 : 0;384}385#endif // STB_DIVIDE_TEST386#endif // STB_DIVIDE_IMPLEMENTATION387#endif // INCLUDE_STB_DIVIDE_H
42 unmodified lines