diff --git a/src/pe/ccd/HashGrids.h b/src/pe/ccd/HashGrids.h
index 4b6392b2d0a8a817549fd6d33da4859b389c7b7e..df5fab20e59f2c4c6ebf02dd09b8c57ba840b251 100644
--- a/src/pe/ccd/HashGrids.h
+++ b/src/pe/ccd/HashGrids.h
@@ -640,9 +640,9 @@ BodyID HashGrids::HashGrid::getRayIntersectingBody(const raytracing::Ray& ray, c
    const int8_t stepY = ray.yDir() >= 0 ? 1 : -1;
    const int8_t stepZ = ray.zDir() >= 0 ? 1 : -1;
    
-   Vec3 near((stepX >= 0) ? (firstCell[0]+1)*cellSpan_-firstPoint[0] : firstPoint[0]-firstCell[0]*cellSpan_,
-             (stepY >= 0) ? (firstCell[1]+1)*cellSpan_-firstPoint[1] : firstPoint[1]-firstCell[1]*cellSpan_,
-             (stepZ >= 0) ? (firstCell[2]+1)*cellSpan_-firstPoint[2] : firstPoint[2]-firstCell[2]*cellSpan_);
+   Vec3 near((stepX >= 0) ? real_c(firstCell[0]+1)*cellSpan_-firstPoint[0] : firstPoint[0]-real_c(firstCell[0])*cellSpan_,
+             (stepY >= 0) ? real_c(firstCell[1]+1)*cellSpan_-firstPoint[1] : firstPoint[1]-real_c(firstCell[1])*cellSpan_,
+             (stepZ >= 0) ? real_c(firstCell[2]+1)*cellSpan_-firstPoint[2] : firstPoint[2]-real_c(firstCell[2])*cellSpan_);
    
    // tMax: distance along the ray to the next cell change in the axis direction
    real_t tMaxX = (!realIsEqual(ray.xDir(), 0)) ? std::abs(near[0]*ray.xInvDir()) : inf;
diff --git a/tests/pe/Raytracing.cpp b/tests/pe/Raytracing.cpp
index 4d227aed1891865068ba447a74ce2cc572197fa9..6f72720bfd4943cc84b2f719f8200d2f59360ddf 100644
--- a/tests/pe/Raytracing.cpp
+++ b/tests/pe/Raytracing.cpp
@@ -753,12 +753,12 @@ void HashGridsTestScene(Raytracer::Algorithm raytracingAlgorithm = Raytracer::RA
    
    // cubes on z = 0 plane
    for (int i = 0; ; ++i) {
-      x_min = forestAABB.xMin() + i*(gap+len);
+      x_min = forestAABB.xMin() + real_c(i)*(gap+len);
       if (x_min > forestAABB.max(0)) {
          break;
       }
       for (int j = 0; ; ++j) {
-         y_min = forestAABB.yMin() + j*(gap+len);
+         y_min = forestAABB.yMin() + real_c(j)*(gap+len);
          if (y_min > forestAABB.max(1)) {
             break;
          }
@@ -769,12 +769,12 @@ void HashGridsTestScene(Raytracer::Algorithm raytracingAlgorithm = Raytracer::RA
    
    //cubes on z = max plane
    for (int i = 0; ; ++i) {
-      x_min = forestAABB.xMin() + i*(gap+len);
+      x_min = forestAABB.xMin() + real_c(i)*(gap+len);
       if (x_min > forestAABB.max(0)) {
          break;
       }
       for (int j = 0; ; ++j) {
-         y_min = forestAABB.yMin() + j*(gap+len);
+         y_min = forestAABB.yMin() + real_c(j)*(gap+len);
          if (y_min > forestAABB.max(1)) {
             break;
          }