simon-git: spigot (master): spigot.git
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Mon Oct 31 20:49:32 GMT 2016
TL;DR:
2793ace Handle exact integer cases of log2 and log10.
Repository: https://git.tartarus.org/simon/spigot.git
On the web: https://git.tartarus.org/?p=simon/spigot.git
Branch updated: master
Committer: spigot.git
Date: 2016-10-31 20:49:32
commit 2793ace18dca363201040a20dc07247752af17da
web diff https://git.tartarus.org/?p=simon/spigot.git;a=commitdiff;h=2793ace18dca363201040a20dc07247752af17da;hp=3e177c2b46f8963b630d1d16421abdff69f05ec5
Author: Simon Tatham <anakin at pobox.com>
Date: Mon Oct 31 20:44:57 2016 +0000
Handle exact integer cases of log2 and log10.
I had occasion today to need log2() to recognise an exact power of 2
and return the result, and annoyingly, it didn't, and instead hung on
an exactness hazard.
The fix for log2 could be more efficient, in that I could have
recognised a power of 2 in the numerator or denominator of a rational
via bit-twiddling of the form (x & (x-1)) == 0. But I prefer doing it
using the spigot system itself, because then it adapts trivially to
other bases, so I get to do log10 the same way.
(Indeed, this way I could even expose a two-operand log_b(a) function
to the user, which would probably be able to spot any case in which b
is rational and a is an integer power of it. Though I suppose it would
be harder to spot _rational_ powers of it - you'd also want, for
example, log_100(10) to return 1/2, and that might be tricker.)
exp.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++----
test.sh | 18 ++++++++++++++++++
2 files changed, 67 insertions(+), 4 deletions(-)
More information about the tartarus-commits
mailing list