spirit-code / spirit

Atomistic Spin Simulation Framework
http://spirit-code.github.io
MIT License
117 stars 52 forks source link

Core: narrowing conversions when `float` is used as type for `scalar` #512

Closed GPMueller closed 5 years ago

GPMueller commented 5 years ago

On MSVC, narrowing conversions are an error, while they are a warning on e.g. gcc. Issues arise when float is used as type for scalar, because of code such as

std::vector<Vector3> Geometry::BravaisVectorsHex2D60()
{
    return { { 0.5*std::sqrt(3), -0.5, 0 },
                { 0.5*std::sqrt(3),  0.5, 0 },
                { 0,   0,                 1 } };
}

or tri_positions[i] = {basis_cell_points[tri[i]].x, basis_cell_points[tri[i]].y, 0};.

This needs to be fixed in order to allow Windows builds of the CUDA version of Spirit.

Side note: for some reason gcc also narrows the 0.5 etc. in the assignment to Vector3 without a warning, which makes it hard to find all occurences on a Linux system.

GPMueller commented 5 years ago

Fixed on branch 'hotfix' with 4c20f855f1670444b51610417c207481238cc1c2, to be merged into a new release. Note that the tri_positions fix needs to be applied to the develop branch.

GPMueller commented 5 years ago

This should be fixed on master with release of v1.8.7 and on develop with 1043fa5220f2ba546403d25e96bd8acf7d67b929.