Topic: Addition of integer_log2() to library fundamentals
Author: Gennaro Prota <gennaro.prota@gmail.com>
Date: Tue, 17 May 2016 00:23:42 +0200
Raw View
Hi,
since the Library Fundamentals TS v2 suggests introducing gcd() and
lcm(), do you think there's room for an integer_log2() function as well?
It would return the integer part of the log base 2 of its argument. It
can be seen here:
<https://github.com/gennaroprota/breath/blob/master/breath/mathematics/integer_log2.hpp>
and
<https://github.com/gennaroprota/breath/blob/master/breath/mathematics/brt/integer_log2.tpp>
The standard version would not be noexcept, as per library guidelines
(the function has the precondition x > 0).
--
Gennaro Prota - C++ developer
I'm looking for a new position.
https://about.me/gennaro.prota
(links to my LinkedIn profile)
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/5f5ff31c-93d1-bedf-a9b4-4cefeea8c613%40gmail.com.
.
Author: "dgutson ." <danielgutson@gmail.com>
Date: Mon, 16 May 2016 19:45:46 -0300
Raw View
--001a113f24f6a6d6420532fd6238
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
El 16/5/2016 19:23, "Gennaro Prota" <gennaro.prota@gmail.com> escribi=C3=B3=
:
>
> Hi,
>
> since the Library Fundamentals TS v2 suggests introducing gcd() and
lcm(), do you think there's room for an integer_log2() function as well? It
would return the integer part of the log base 2 of its argument. It can be
seen here:
>
>
> <
https://github.com/gennaroprota/breath/blob/master/breath/mathematics/integ=
er_log2.hpp
>
>
> and
>
>
> <
https://github.com/gennaroprota/breath/blob/master/breath/mathematics/brt/i=
nteger_log2.tpp
>
Two questions: 1) why it is not a template, and 2) why n is a signed
integer in the private functions?
>
> The standard version would not be noexcept, as per library guidelines
(the function has the precondition x > 0).
>
> --
> Gennaro Prota - C++ developer
> I'm looking for a new position.
> https://about.me/gennaro.prota
> (links to my LinkedIn profile)
>
> --
> You received this message because you are subscribed to the Google Groups
"ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> To view this discussion on the web visit
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/5f5ff31c-93d1-=
bedf-a9b4-4cefeea8c613%40gmail.com
..
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/CAFdMc-3hdv-zXc0oyu8SOnGb%2BigNPV5nU4fTtiSd6Den_=
d9fbg%40mail.gmail.com.
--001a113f24f6a6d6420532fd6238
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p dir=3D"ltr"><br>
El 16/5/2016 19:23, "Gennaro Prota" <<a href=3D"mailto:gennaro=
..prota@gmail.com">gennaro.prota@gmail.com</a>> escribi=C3=B3:<br>
><br>
> Hi,<br>
><br>
> since the Library Fundamentals TS v2 suggests introducing gcd() and lc=
m(), do you think there's room for an integer_log2() function as well? =
It would return the integer part of the log base 2 of its argument. It can =
be seen here:<br>
><br>
><br>
> <<a href=3D"https://github.com/gennaroprota/breath/blob/master/brea=
th/mathematics/integer_log2.hpp">https://github.com/gennaroprota/breath/blo=
b/master/breath/mathematics/integer_log2.hpp</a>><br>
><br>
> and<br>
><br>
><br>
> <<a href=3D"https://github.com/gennaroprota/breath/blob/master/brea=
th/mathematics/brt/integer_log2.tpp">https://github.com/gennaroprota/breath=
/blob/master/breath/mathematics/brt/integer_log2.tpp</a>></p>
<p dir=3D"ltr">Two questions: 1) why it is not a template, and 2) why n is =
a signed integer in the private functions?</p>
<p dir=3D"ltr">><br>
> The standard version would not be noexcept, as per library guidelines =
(the function has the precondition x > 0).<br>
><br>
> -- <br>
> Gennaro Prota - C++ developer<br>
> =C2=A0I'm looking for a new position.<br>
> =C2=A0<a href=3D"https://about.me/gennaro.prota">https://about.me/genn=
aro.prota</a><br>
> =C2=A0(links to my LinkedIn profile)<br>
><br>
> -- <br>
> You received this message because you are subscribed to the Google Gro=
ups "ISO C++ Standard - Future Proposals" group.<br>
> To unsubscribe from this group and stop receiving emails from it, send=
an email to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-=
proposals+unsubscribe@isocpp.org</a>.<br>
> To post to this group, send email to <a href=3D"mailto:std-proposals@i=
socpp.org">std-proposals@isocpp.org</a>.<br>
> To view this discussion on the web visit <a href=3D"https://groups.goo=
gle.com/a/isocpp.org/d/msgid/std-proposals/5f5ff31c-93d1-bedf-a9b4-4cefeea8=
c613%40gmail.com">https://groups.google.com/a/isocpp.org/d/msgid/std-propos=
als/5f5ff31c-93d1-bedf-a9b4-4cefeea8c613%40gmail.com</a>.<br>
</p>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAFdMc-3hdv-zXc0oyu8SOnGb%2BigNPV5nU4=
fTtiSd6Den_d9fbg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAFdMc-3hdv-zXc=
0oyu8SOnGb%2BigNPV5nU4fTtiSd6Den_d9fbg%40mail.gmail.com</a>.<br />
--001a113f24f6a6d6420532fd6238--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Mon, 16 May 2016 18:33:44 -0700
Raw View
On ter=C3=A7a-feira, 17 de maio de 2016 00:23:42 PDT Gennaro Prota wrote:
> since the Library Fundamentals TS v2 suggests introducing gcd() and=20
> lcm(), do you think there's room for an integer_log2() function as well?=
=20
The integer part of the logarithm of base 2 of an integral number is simply=
=20
the 1-based position of the highest bit set. So that is already taken care =
of=20
by the clz() function (count leading zeroes) or the fls one (find last set)=
..
In terms of one another:
// Returns the number of leading zeroes (before the most significant bit)
int clz(T value)
{
return sizeof(T) =3D=3D 8 : __builtin_clzll(value) ?
sizeof(T) =3D=3D 4 ? __builtin_clz(value) :=20
__builtin_clzs(value);
// T ret;
// asm("lzcnt %1, %2" : "=3Dr" (ret) : "r" (value));
// return ret;
}
// Returns the position of the last (most significant) bit set in \a value.
// The least significant bit is position 1 and the most significant is 32 o=
r 64.
int fls(T value)
{
return sizeof(value) * CHAR_BIT - clz(value);
// also:
return (sizeof(value) * CHAR_BIT - 1) ^ clz(value);
}
int integer_log_2(T value)
{
return fls(value);
}
--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/21524674.mjVuaPWFuQ%40tjmaciei-mobl4.
.
Author: gennaro.prota@gmail.com
Date: Mon, 16 May 2016 21:51:51 -0700 (PDT)
Raw View
------=_Part_13_1455628987.1463460711935
Content-Type: multipart/alternative;
boundary="----=_Part_14_224680032.1463460711936"
------=_Part_14_224680032.1463460711936
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Tuesday, May 17, 2016 at 12:45:48 AM UTC+2, dgutson wrote:
>
>
> El 16/5/2016 19:23, "Gennaro Prota" <gennar...@gmail.com <javascript:>>=
=20
> escribi=C3=B3:
> >
> > Hi,
> >
> > since the Library Fundamentals TS v2 suggests introducing gcd() and=20
> lcm(), do you think there's room for an integer_log2() function as well? =
It=20
> would return the integer part of the log base 2 of its argument. It can b=
e=20
> seen here:
> >
> >
> > <
> https://github.com/gennaroprota/breath/blob/master/breath/mathematics/int=
eger_log2.hpp
> >
> >
> > and
> >
> >
> > <
> https://github.com/gennaroprota/breath/blob/master/breath/mathematics/brt=
/integer_log2.tpp=20
> <https://www.google.com/url?q=3Dhttps%3A%2F%2Fgithub.com%2Fgennaroprota%2=
Fbreath%2Fblob%2Fmaster%2Fbreath%2Fmathematics%2Fbrt%2Finteger_log2.tpp&sa=
=3DD&sntz=3D1&usg=3DAFQjCNGOaaAzmNtxPRbhlPVJsWgeeDcxrw>
> >
>
> Two questions: 1) why it is not a template, and 2) why n is a signed=20
> integer in the private functions?
>
>
> 1) It isn't a function template because it doesn't need to be: the=20
uintmax_t argument covers all possible cases. Alternatively, it might be a=
=20
intmax_t (signed).
2) n has the same type as the result, i.e. int; this is in-line with what=
=20
numeric_limits<> does.
--=20
Gennaro Prota - C++ developer
I'm looking for a new position.
https://about.me/gennaro.prota
(links to my LinkedIn profile)
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/45f882d5-2ca0-446a-b9d6-5e890333c6df%40isocpp.or=
g.
------=_Part_14_224680032.1463460711936
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, May 17, 2016 at 12:45:48 AM UTC+2, dgutson wro=
te:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;"><p dir=3D"ltr"><br>
El 16/5/2016 19:23, "Gennaro Prota" <<a href=3D"javascript:" t=
arget=3D"_blank" gdf-obfuscated-mailto=3D"WywWZNLrCQAJ" rel=3D"nofollow" on=
mousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"thi=
s.href=3D'javascript:';return true;">gennar...@gmail.com</a>> es=
cribi=C3=B3:<br>
><br>
> Hi,<br>
><br>
> since the Library Fundamentals TS v2 suggests introducing gcd() and lc=
m(), do you think there's room for an integer_log2() function as well? =
It would return the integer part of the log base 2 of its argument. It can =
be seen here:<br>
><br>
><br>
> <<a href=3D"https://github.com/gennaroprota/breath/blob/master/brea=
th/mathematics/integer_log2.hpp" target=3D"_blank" rel=3D"nofollow" onmouse=
down=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fgith=
ub.com%2Fgennaroprota%2Fbreath%2Fblob%2Fmaster%2Fbreath%2Fmathematics%2Fint=
eger_log2.hpp\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEtLZQAnPZjtKL8CdOzQ4G=
I84DSrg';return true;" onclick=3D"this.href=3D'https://www.google.c=
om/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fgennaroprota%2Fbreath%2Fblob%2Fmaste=
r%2Fbreath%2Fmathematics%2Finteger_log2.hpp\x26sa\x3dD\x26sntz\x3d1\x26usg\=
x3dAFQjCNEtLZQAnPZjtKL8CdOzQ4GI84DSrg';return true;">https://github.com=
/<wbr>gennaroprota/breath/blob/<wbr>master/breath/mathematics/<wbr>integer_=
log2.hpp</a>><br>
><br>
> and<br>
><br>
><br>
> <<a href=3D"https://www.google.com/url?q=3Dhttps%3A%2F%2Fgithub.com=
%2Fgennaroprota%2Fbreath%2Fblob%2Fmaster%2Fbreath%2Fmathematics%2Fbrt%2Fint=
eger_log2.tpp&sa=3DD&sntz=3D1&usg=3DAFQjCNGOaaAzmNtxPRbhlPVJsWg=
eeDcxrw" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'=
;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fgennaroprota%2F=
breath%2Fblob%2Fmaster%2Fbreath%2Fmathematics%2Fbrt%2Finteger_log2.tpp\x26s=
a\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGOaaAzmNtxPRbhlPVJsWgeeDcxrw';retur=
n true;" onclick=3D"this.href=3D'https://www.google.com/url?q\x3dhttps%=
3A%2F%2Fgithub.com%2Fgennaroprota%2Fbreath%2Fblob%2Fmaster%2Fbreath%2Fmathe=
matics%2Fbrt%2Finteger_log2.tpp\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGOa=
aAzmNtxPRbhlPVJsWgeeDcxrw';return true;">https://github.com/<wbr>gennar=
oprota/breath/blob/<wbr>master/breath/mathematics/brt/<wbr>integer_log2.tpp=
</a>></p>
<p dir=3D"ltr">Two questions: 1) why it is not a template, and 2) why n is =
a signed integer in the private functions?</p>
<p dir=3D"ltr"><br></p></blockquote><div>1) It isn't a function templat=
e because it doesn't need to be: the uintmax_t argument covers all poss=
ible cases. Alternatively, it might be a intmax_t (signed).<br><br>2) n has=
the same type as the result, i.e. int; this is in-line with what numeric_l=
imits<> does.<br><br>-- <br>Gennaro Prota - C++ developer<br>=C2=A0I&=
#39;m looking for a new position.<br>=C2=A0https://about.me/gennaro.prota<b=
r>=C2=A0(links to my LinkedIn profile)<br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/45f882d5-2ca0-446a-b9d6-5e890333c6df%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/45f882d5-2ca0-446a-b9d6-5e890333c6df=
%40isocpp.org</a>.<br />
------=_Part_14_224680032.1463460711936--
------=_Part_13_1455628987.1463460711935--
.