Skip to content

abs in dfm.io/content/downloads/notebooks/stan-c++.ipynb #2

Description

@christophernhill

@dfm I was using your excellent notebook to learn about how to call C++ from PyStan. The features are in the develop branch of PyStan and gets picked up by conda, which is great.

I came across one line
if (abs((E - E0) / E) <= 1.234e-10) return E;
in the C++ code in cell 4 and cell 17 that caused a problem for my gcc/g++ stack (GCC 7.4).

Changing this line to read
if (fabs((E - E0) / E) <= 1.234e-10) return E;
fixes the problem.

Posting this, in case others run into it.

The origin of the issue is discussed in Stack Overflow here.
The use of abs() is strictly correct C++, so this isn't really a bug - but it may be useful to others to know this trick.

The C++ extension is excellent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions