Skip to content

Possible bug in dmd for Windows converting known numbers into -nan #3

@davidomarf

Description

@davidomarf

This problems was spotted first when running dub run after pulling 36e4700.

First, source/app.d calls heightmapPerspectiveTest() defined at source/tests/heightmap-perspective.d

heightmapPerspectiveTest(), at line 68, calls fillByHeightFunction(), defined as

void fillByHeightFunction(HeightFunction heightFunction)
{
for (uint i; i < m_xlength; i++)
for (uint j; j < m_ylength; j++)
this[i, j] = heightFunction(cast(float) i / m_xlength, cast(float) j / m_ylength);
}

using QuevHeightFunction() as argument for heightFunction, defined in source/heightmap/quev.d.

QuevHeightFunction() is specified to receive (double x, double y) as arguments.

double opCall(double x, double y)

And fillByHeightFunction was sending them.

this[i, j] = heightFunction(cast(float) i / m_xlength, cast(float) j / m_ylength);

At least theoretically.


At the first iteration, QuevHeightFunction() should be receiving 0, 0, but it was receiving -nan, 0.

My conclusion was that error must have been coming from fillByHeightFunction().

Before calling heightFunction(cast(double) i / m_xlength, cast(double) j / m_ylength);, all i, m_xlength, j, m_ylength were numbers.

And so were the operations i / m_xlength and j / m_ylength.

And so were the casts cast(double) i / m_xlength and cast(double) j / m_ylength).


tl;dr

QuevHeightFunction() is called with two floats (x, y). But it receives (-nan, y).

This suggests that something happens at the moment of the function call.

Possible Solution

The only solution that I've found so far was writing the value of cast(double) i / m_xlength to console before sending it to QuevHeightFunction().

Yes. Only that. Printing.

Steps to Reproduce

(Assuming you've already cloned the repository)

  1. git pull origin master
  2. git checkout heightmap-perspective-test
  3. git checkout 36e47004629bbe8900da9570c0271c5a18badc57
  4. dub run

Environment

  • DMD: v2.081.1
  • DUB: 1.10.0
  • OS: Windows 10 1803

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions