Math.log2 applied to powers of 2
Kevin Reid
kpreid at google.com
Thu Sep 18 11:12:42 PDT 2014
On Thu, Sep 18, 2014 at 10:56 AM, Tab Atkins Jr. <jackalmage at gmail.com>
wrote:
> On Thu, Sep 18, 2014 at 3:17 AM, Claude Pache <claude.pache at gmail.com>
> wrote:
> > Question: Should Math.log2 give exact results for powers of 2?
> >
> > The same issue holds for Math.log10 (might be applicable for nonnegative
> > powers only): Math.log10(1e15) != 15 in Chrome.
>
> I have no idea of the computation complexity underlying a log
> implementation, so given that: yes, it should totally give exact
> results for powers of 2, and log10 should do the same for (positive)
> powers of 10. (Negative powers of 10 can't actually be represented by
> a JS number, so there's no need to talk about them.)
It would also be useful, though perhaps not feasible, if they are
guaranteed to be monotonic everywhere and strictly monotonic near those
exact values; that is,
for all x < 2^k, log2(x) < k
for all x > 2^k, log2(x) > k
and similarly for log10. If this property held, then naïve "number of
digits" tests expressed using logarithms would always give the right
answers. (This probably conflicts with generally desirable rounding
properties, however.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140918/33c994de/attachment.html>
More information about the es-discuss
mailing list