Re: [Seed7-users] Seed7 Compilation Errors
Interpreter and compiler for the Seed7 programming language.
Brought to you by:
thomas_mertes
From: Thomas M. <tho...@gm...> - 2021-04-22 20:04:59
|
Hi Zachary, Sorry for the delay, I was rather busy with graphic formats. You write: > Hey Thomas, > > Unfortunately I am still getting errors. However, this time I modified the > chkflt.sd7 program to output the result of the trunc() and round() operations > I'm not sure why I didn't think of this before. > I've attached the files so you can see for yourself, but it appears that > truncating or rounding 9223372036854775807.0 results in -9223372036854775808. > Which you did mention was a possibility in your last e-mail. > > Does this mean something like > "and trunc(9223372036854775807.0) <> -9223372036854775808" is needed? No, it probably means that MAXIMUM_TRUNC_ARGUMENT has the wrong value. For some reason chkccomp.c does not compute MAXIMUM_TRUNC_ARGUMENT correct on your computer. I created a test program: ========== begin chktrunc.c ========== #include "stdio.h" #include "float.h" #include "version.h" #include "common.h" double maxFltValues[] = { -9223372036854773760.0, -9223372036854774784.0, -9223372036854775808.0, -9223372036854777856.0, 9223372036854773760.0, 9223372036854774784.0, 9223372036854775808.0, 9223372036854777856.0 }; int64Type maxIntValues[] = { -9223372036854773760, -9223372036854774784, -9223372036854775807-1, -1234567890123456789, 9223372036854773760, 9223372036854774784, 9223372036854775807, 1234567890123456789}; int main (int argc, char *argv[]) { int pos; char *outcome[] = {"fail ", "success"}; int64Type minimumTruncArgument; int64Type maximumTruncArgument; for (pos = 0; pos < 8; pos++) { printf("%f: " FMT_D " %s " FMT_D " %f %d %d %d %d\n", maxFltValues[pos], maxIntValues[pos], outcome[(int64Type) maxFltValues[pos] == maxIntValues[pos]], (int64Type) maxFltValues[pos], (double) maxIntValues[pos], maxFltValues[pos] < (double) -9223372036854774784, maxFltValues[pos] > (double) 9223372036854774784, maxFltValues[pos] < (double) -9223372036854775807-1, maxFltValues[pos] > (double) 9223372036854775807); } for (pos = 0; pos < 4; pos++) { if ((int64Type) maxFltValues[pos] == maxIntValues[pos]) { minimumTruncArgument = maxIntValues[pos]; } } for (pos = 4; pos < 8; pos++) { if ((int64Type) maxFltValues[pos] == maxIntValues[pos]) { maximumTruncArgument = maxIntValues[pos]; } } printf("#define MINIMUM_TRUNC_ARGUMENT " FMT_D "\n", minimumTruncArgument); printf("#define MAXIMUM_TRUNC_ARGUMENT " FMT_D "\n", maximumTruncArgument); return 0; } ========== end chktrunc.c ========== This program includes version.h and common.h. You can it compile and run with: gcc chktrunc.c -o chktrunc ./chktrunc On my computer this results in: -9223372036854773760.000000: -9223372036854773760 success -9223372036854773760 -9223372036854773760.000000 0 0 0 0 -9223372036854774784.000000: -9223372036854774784 success -9223372036854774784 -9223372036854774784.000000 0 0 0 0 -9223372036854775808.000000: -9223372036854775808 success -9223372036854775808 -9223372036854775808.000000 1 0 0 0 -9223372036854777856.000000: -1234567890123456789 fail -9223372036854775808 -1234567890123456768.000000 1 0 1 0 9223372036854773760.000000: 9223372036854773760 success 9223372036854773760 9223372036854773760.000000 0 0 0 0 9223372036854774784.000000: 9223372036854774784 success 9223372036854774784 9223372036854774784.000000 0 0 0 0 9223372036854775808.000000: 9223372036854775807 fail -9223372036854775808 9223372036854775808.000000 0 1 0 0 9223372036854777856.000000: 1234567890123456789 fail -9223372036854775808 1234567890123456768.000000 0 1 0 1 #define MINIMUM_TRUNC_ARGUMENT -9223372036854775808 #define MAXIMUM_TRUNC_ARGUMENT 9223372036854774784 Part of chktrunc.c is code that I use in an improved chkccomp.c. Please run it on your computer and tell me the results. Regards Thomas |