The only alternative I could find (quickly) is to use round() instead of trunc(), also, putting 36.761 in the formula gives the correct result.
Well.....
After fiddling a bit with trunc and round, I looked up the trunc function in the sourcecode. It is mentioned there, in the system unit, that 'compiler magic' is to be performed on some routines, including trunc, sin and some more. Then, after seeing that trunc is implemented in quite simple asm code, (I can't really read it, wrote some long tome ago, but have seen the hang of it) I concluded that it might be that by the way of handling parameters there, it is possible that sometimes a bit falls off of a value. Replacing the requested function with:
Code:
var d : double; h : integer;
...
h := 100;
d := 36.76 * h;
result := trunc(d) / h);
gives the correct result, and changing d from double to extended (the default parametertype for trunc) gives me back the *wrong* result again! s-) So I conclude that my conclusion on trunc is correct, passing specific values as type extended to trunc can chop off the wrong bits...
Best workaround would be to first place the value in another 'real' type than extended, then apply the math.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.