Re: [fpc-devel] Compile time functions

2018-07-21 Thread Sven Barth via fpc-devel
Martok schrieb am Sa., 21. Juli 2018, 17:12: > Am 21.07.2018 um 02:08 schrieb Sven Barth via fpc-devel: > > The main problem is that not all functions that would be eligible for > your > > approach are also declared as inline thus their node trees would not be > stored > > inside the PPU and

Re: [fpc-devel] Compile time functions

2018-07-21 Thread Martok
Am 21.07.2018 um 02:08 schrieb Sven Barth via fpc-devel: > The main problem is that not all functions that would be eligible for your > approach are also declared as inline thus their node trees would not be stored > inside the PPU and thus you could not work with them. I'm not sure I understand.

Re: [fpc-devel] Compile time functions

2018-07-21 Thread J. Gareth Moreton
Sorry for that mess of a formatting on the code sample, Here is a much nicer version! function Binomial(n, r: Cardinal): Cardinal; pure;begin   if (r > n) then     Result := 0   else if (r = n) then     Result := 1 { Faster than calculating the factorials }   else     Result :=

Re: [fpc-devel] Compile time functions

2018-07-21 Thread J. Gareth Moreton
An interesting read. If you can collapse an inline function into a single assignment in most situations, then brilliant! Definitely keep that optimisation in. While there are many similarities and prerequisites between an inline function and a pure function, and many simple mathematical

Re: [fpc-devel] Compile time functions

2018-07-21 Thread J. Gareth Moreton
To follow up on this, even if you rewrote the function to use a multiplicative formula (faster to compute overall): function Binomial(n, r: Cardinal): Cardinal; pure;var  c: Cardinal; begin   for (r > n) then     Result := 0   else     begin       Result := 1;   if n r then