Origins of the D Programming Language

Russel Winder russel at winder.org.uk
Tue Dec 4 07:31:28 UTC 2018


On Mon, 2018-12-03 at 23:42 +0000, Q. Schroll via Digitalmars-d wrote:
> […]
> 
> ulong factorial(ulong n) {
>    ulong result = 1;
>    foreach (i; 0 .. n) result *= i; // off by one.
>    return result;
> }
> 
> Even the best make mistake ;)

Being serious for a moment: anyone implementing factorial using ulong is doing
it wrong.  std.bigint.BigInt is the only type that makes sense in a D
implementation of factorial – also fibonacci.

And remember, these calculations are actually required in many bioinformatics
and hedge fund models. Trust me on this, I found out the hard way presenting
Python workshops to such folk. Fortunately, in Python int means either
hardware int or software "big integer" depending on value. Except when using
NumPy which is when things get tricky.
  
-- 
Russel.
===========================================
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20181204/f70b691b/attachment.sig>


More information about the Digitalmars-d mailing list