uses c89:stdio as io; int fail(char^ s) { io:fprintf(io:stderr, "Failure: %s\n", s); return 0; } // TODO math functions in LRL import linkname "fabs" float fabs_f(float x); import linkname "fabsf" cfloat fabs_cf(cfloat x); import linkname "fabs" cfloat fabs_cd(cdouble x); int f() { // use variables with constants to avoid constexpr from optimizing out // the modulo expressions below. var eint8 c17 = 17; var eint8 c123 = 123; var eint16 c31999 = 31999; var uint16 c65123 = 65123; // unsigned integer byte b = 253 mod c17; uint ui = 65321 mod c65123; // TODO add larger int types //uint64 ui64 = 18446744073709551615 mod 18446744073709551615; ulong ul = 456 mod c123; if b != 15 return fail("253 mod 17 != 15"); if ui != 198 return fail("65321 mod 65123 != 198"); if ul != 87 return fail("456 mod 123 != 87"); // signed integer int8 s8a = -123 mod c17; int8 s8b = 123 mod -c17; int8 s8c = -123 mod -c17; int sia = -32000 mod c31999; int sib = 32000 mod -c31999; int sic = -32000 mod -c31999; // TODO add larger int types //int64 si64a = 9223372036854775807 mod 9223372036854775807; // TODO fix type of smallest signed integer values //int64 si64b = -9223372036854775808 mod 9223372036854775807; //int64 si64c = 9223372036854775807 mod -9223372036854775808; //int64 si64d = -9223372036854775808 mod -9223372036854775808; long sl = -456 mod -c123; if s8a != 13 return fail("-123 mod 17 != 13"); if s8b != -13 return fail("123 mod -17 != -13"); if s8c != -4 return fail("-123 mod -17 != -4"); if sia != 31998 return fail("-32000 mod 31999 != 31998"); if sib != -31998 return fail("32000 mod -31999 != -31998"); if sic != -1 return fail("-32000 mod -31999 != -1"); if sl != -87 return fail("-456 mod -123 != -87"); // floating point float fa = 2.34 mod 1.23; float fb = -2.34 mod 1.23; float fc = 2.34 mod -1.23; float fd = -2.34 mod -1.23; cfloat cfa = 2.34 mod 1.23; cfloat cfb = -2.34 mod 1.23; cfloat cfc = 2.34 mod -1.23; cfloat cfd = -2.34 mod -1.23; cdouble cda = 2.34 mod 1.23; cdouble cdb = -2.34 mod 1.23; cdouble cdc = 2.34 mod -1.23; cdouble cdd = -2.34 mod -1.23; if fabs_f( fa - 1.11) > 0.1 as float return fail("2.34 mod 1.23 != 1.11"); if fabs_f( fb - 0.12) > 0.1 as float return fail("-2.34 mod 1.23 != 0.12"); if fabs_f( fc - -0.12) > 0.1 as float return fail("2.34 mod -1.23 != -0.12"); if fabs_f( fd - -1.11) > 0.1 as float return fail("-2.34 mod -1.23 != -1.10"); if fabs_cf(cfa - 1.11) > 0.1 as cfloat return fail("2.34 mod 1.23 != 1.11"); if fabs_cf(cfb - 0.12) > 0.1 as cfloat return fail("-2.34 mod 1.23 != 0.12"); if fabs_cf(cfc - -0.12) > 0.1 as cfloat return fail("2.34 mod -1.23 != -0.12"); if fabs_cf(cfd - -1.11) > 0.1 as cfloat return fail("-2.34 mod -1.23 != -1.10"); if fabs_cd(cda - 1.11) > 0.1 as cdouble return fail("2.34 mod 1.23 != 1.11"); if fabs_cd(cdb - 0.12) > 0.1 as cdouble return fail("-2.34 mod 1.23 != 0.12"); if fabs_cd(cdc - -0.12) > 0.1 as cdouble return fail("2.34 mod -1.23 != -0.12"); if fabs_cd(cdd - -1.11) > 0.1 as cdouble return fail("-2.34 mod -1.23 != -1.10"); return 1; } // TODO run the test code above somehow /*linkname "main" int main() { f(); }*/