[fpc-pascal] Floating point question

Bernd Oppolzer bernd.oppolzer at t-online.de
Tue Feb 13 11:39:06 CET 2024


Am 13.02.2024 um 10:54 schrieb Michael Van Canneyt via fpc-pascal:
>
>
> On Tue, 13 Feb 2024, James Richters via fpc-pascal wrote:
>
>> Sorry for the kind of duplicate post, I submitted it yesterday 
>> morning and I
>> thought it failed, so I re-did it and tried again.. then after that the
>> original one showed up.
>>
>> A thought occurred to me.   Since the complier math is expecting all the
>> constants would be in full precision, then the compiler math doesn't 
>> need to
>> change, it's just that the reduction in precision is just happening too
>> soon.  It's evaluating and reducing each term of an expression, then the
>> math is happening, and the answer is not coming out right.
>>
>> If instead everything was left full precision until after the 
>> compiler math
>> (because this is what the compiler math expects), and then the final 
>> answer
>> was reduced in precision where possible, then it would work 
>> flawlessly.  So
>> the reduction in precision function only needs to run once on the final
>> answer, not on every term before the calculation.
>
> As Jonas said, this would result in less efficient code, since all the 
> math will then be done at full precision, which is slower.
>
> As usual, it is a trade-off between size (=precision) and speed.
>
> Michael.


But, sorry, because we are talking about compile time math, performance 
(nanoseconds) in this case doesn't count, IMO.




More information about the fpc-pascal mailing list