4 ms·
> A great example would be a math function like log2. That function should work for every case that you need to calculate a logarithm – each call is fundamental
by jbay808 6y ago
> A great example would be a math function like log2. That function should work for every case that you need to calculate a logarithm – each call is fundamentally the same.
Even in the case of log2, some log2s might need to be fast approximations, others accurate down to the LSB, some operating on complex numbers, and others on array-like data...
- contravariant 6y agoIt's still correct in the sense that you shouldn't repeat the code for calculating the logarithm in every single scenario where you need one. Of course if you need a function for a different purpose then it makes sense to make another one. Of course mathematics is always an endless game of expanding and contracting definitions so might need some additional versions anyway (most commonly something like f(x) = log(1+x)), though if you're clever about it you can rephrase most of what you want with existing functions.