Marius Gedminas wrote:
I have written an expression parser and evaluator in Borland Pascal and I do not use calculators any more (besides most of them do not have 18 digit precision, not to mention another functionality). In the past I have relied on BP run-time system to show only `accurate' (I hope you understand what I have in mind ;) digits and it would be very great if I could rely on GPC too. I do not request this to be the default behavior, but I would want to know of a way to achieve it.
The file float.h contains a number of useful constants, e.g. {FLT,DBL,LDBL}_MANT_DIG for the number of digits is the internal radix, and even {FLT,DBL,LDBL}_DIG for the number of decimal digits. (You may have to generate a correct version with enquire -- e.g., mine had the same values for long reals as for reals. I wonder if the GCC installation shouldn't do this automatically.)
So, there's only the problem how to get the constants into a Pascal program:
- Directly including the file doesn't work because of the C comments in it. (BTW, how about an option for the Pascal preprocessor to accept C comments? AFAICS, they can't occur in a legal Pascal program, anyway.)
- One could write a small C wrapper, as always.
- The GPC installation could Pascalify this file, i.e. remove or Pascalify the comments, remove the "F" and "L" postfixes from some numbers, and perhaps translate the defines into constants and make a unit out of it. This does not seem very difficult to do. I think the following sed script should do the job -- at least it does on my machine (sorry for the long line ;-):
sed 's,/*,{,;s,*/,},;/^#undef/d;/FLOAT_H/d;s/float.h/Automatically generated from &/;s/#define[[:space:]]*([A-Za-z0-9_]*)[[:space:]]*([-+0-9.Ee()]*)[FfLl]?$/const \1 = \2;/'
The resulting declarations could be merged with the RTS, e.g. by including them into into gpc.pas which contains most RTS declarations.
So, we only have to tell the makefiles to do this, and then, I think, it would be the best solution.
Frank