Talk:Pi
From Free Pascal wiki
Jump to navigationJump to search
"This gives you the chance to shadow (redefine) pi()"
What does that mean? --Bart (talk) 15:05, 24 January 2018 (CET)
- You can write in your own
program
/unit
function pi(): valReal;
begin
pi := 3.0;
end;
- and in the current scope expressions like
3*pi()
will result in9.0
. To access “a more precise” definition of π you can/have to write3*system.pi()
(characteristic of shadowing: re-defining identifiers, but the original identifier remains accessible). Kai Burghardt (talk) 16:42, 24 January 2018 (CET)- OK, Wikipedia understands as “shadowing” “variable shadowing”, not necessarily of functions. But “overloading” though, is defining the same identifier with differing formal signatures (accepted parameters). You know a better term, Bart? Kai Burghardt (talk) 16:47, 24 January 2018 (CET)
- But this you could also do if Pi was a constant, isn't it?
const pi{: valReal} = 3.0;
- Huh, well, indeed. Then I don't know, why
pi
was implemented as a function and not a as a simpleconst
. Maybe some historical reason? Perhaps some targets, some FPUs provide a pi-function on their own? [which you usually want to use] Kai Burghardt (talk) 17:26, 27 January 2018 (CET)
- Huh, well, indeed. Then I don't know, why