Bug 13369 – std.math.iLog10

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-08-24T16:09:24Z
Last change time
2024-12-01T16:22:13Z
Keywords
trivial
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: phobos#10081 →

Comments

Comment #0 by bearophile_hugs — 2014-08-24T16:09:24Z
I suggest to add to Phobos an overloaded function like this: uint iLog10(in uint x) pure nothrow @safe @nogc in { assert(x > 0); } body { return (x >= 1_000_000_000) ? 9 : (x >= 100_000_000) ? 8 : (x >= 10_000_000) ? 7 : (x >= 1_000_000) ? 6 : (x >= 100_000) ? 5 : (x >= 10_000) ? 4 : (x >= 1_000) ? 3 : (x >= 100) ? 2 : (x >= 10) ? 1 : 0; } uint iLog10(in ulong x) pure nothrow @safe @nogc in { assert(x > 0); } body { return (x >= 10_000_000_000_000_000_000UL) ? 19 : (x >= 1_000_000_000_000_000_000UL) ? 18 : (x >= 100_000_000_000_000_000UL) ? 17 : (x >= 10_000_000_000_000_000UL) ? 16 : (x >= 1_000_000_000_000_000UL) ? 15 : (x >= 100_000_000_000_000UL) ? 14 : (x >= 10_000_000_000_000UL) ? 13 : (x >= 1_000_000_000_000UL) ? 12 : (x >= 100_000_000_000UL) ? 11 : (x >= 10_000_000_000UL) ? 10 : (x >= 1_000_000_000UL) ? 9 : (x >= 100_000_000UL) ? 8 : (x >= 10_000_000UL) ? 7 : (x >= 1_000_000UL) ? 6 : (x >= 100_000UL) ? 5 : (x >= 10_000UL) ? 4 : (x >= 1_000UL) ? 3 : (x >= 100UL) ? 2 : (x >= 10UL) ? 1 : 0; } See also Issue 9762 .
Comment #1 by bearophile_hugs — 2014-08-25T08:40:01Z
An example of the risks of using ceil(log10): void main() { import std.stdio, std.math; immutable x = 10 ^^ 7; writefln("%1.20f", x.log10); writeln(x.log10.ceil); } Output: 7.00000000000000000040 8
Comment #2 by b2.temp — 2015-12-01T21:41:25Z
Hi, bearophile. Just a word to tell you that your spam is part of the history ;) http://forum.dlang.org/post/[email protected] Your bullshits are almost done. Goodbye my friend, it's hard to die...
Comment #3 by ag0aep6g — 2015-12-02T06:30:46Z
(In reply to bb.temp from comment #2) > Hi, bearophile. > > Just a word to tell you that your spam is part of the history ;) > > http://forum.dlang.org/post/[email protected] > > Your bullshits are almost done. > > Goodbye my friend, it's hard to die... This is inappropriate. Please don't take personal matters to issue discussions, and whatever the channel, please stay civil.
Comment #4 by robert.schadek — 2024-12-01T16:22:13Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10081 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB