<cmath> and std:: vs. <math.h> and ::

197 views
Skip to first unread message

Bob Carpenter

unread,
May 22, 2015, 6:42:15 PM5/22/15
to stan...@googlegroups.com
[moved off issue, changed subject]

The original question is why so many "using std::log" and
whatnot in the code now?

We're moving to consistently using <cmath>, the C++
math library where the functions are declared in the
standard library (std::) namespace. <math.h> is the C version
and brings in functions in the top-level (::) namespace. Thus
the <math.h> versions are always in scope because the symbols
from a containing namespace area always available in nested
namespaces. So anything defined in stan:: would be visible
in stan::math, for example.

It's better not to bring namespaces in wholesale to gain
more control on what might get called.

- Bob

> On May 22, 2015, at 10:29 AM, Daniel Lee <notifi...@github.com> wrote:
>
> @randommm, sorry about the delay.
>
> I think it happened because we've started to be more careful about the namespace. In the past when, when we used log, we used to pick up the ::log from <cmath> or <math.h> and stan::agrad::log from <stan/math/rev/prim/scal/fun/log.hpp>.
>
> (now that I wrote that out, it doesn't feel so satisfying an answer; sorry -- I've got nothing better)
>
> —
> Reply to this email directly or view it on GitHub.
>

Marco Inacio

unread,
May 24, 2015, 8:00:00 PM5/24/15
to stan...@googlegroups.com
Thanks for taking the time to explain it.
Reply all
Reply to author
Forward
0 new messages