From 5c4f8abd24d5ac9a34781969ba4261beff9cc17a Mon Sep 17 00:00:00 2001 From: Camille Date: Sun, 24 Sep 2017 13:06:10 +0200 Subject: [PATCH] Fix type promotion in math function --- .../3d_render_raytracing/PerlinNoise.cpp | 21 ++++++++++--------- .../3d_rendering/3d_render_raytracing/ray.cpp | 8 ++++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/PerlinNoise.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/PerlinNoise.cpp index daf4fd3217..523edb619d 100644 --- a/3d-viewer/3d_rendering/3d_render_raytracing/PerlinNoise.cpp +++ b/3d-viewer/3d_rendering/3d_render_raytracing/PerlinNoise.cpp @@ -40,6 +40,7 @@ */ #include "PerlinNoise.h" +#include #include #include #include @@ -97,14 +98,14 @@ PerlinNoise::PerlinNoise( unsigned int seed ) float PerlinNoise::noise( float x, float y, float z ) const { // Find the unit cube that contains the point - int X = (int) ((float)floor( x )) & 255; - int Y = (int) ((float)floor( y )) & 255; - int Z = (int) ((float)floor( z )) & 255; + int X = static_cast( std::floor( x ) ) & 255; + int Y = static_cast( std::floor( y ) ) & 255; + int Z = static_cast( std::floor( z ) ) & 255; // Find relative x, y,z of point in cube - x -= (float)floor( x ); - y -= (float)floor( y ); - z -= (float)floor( z ); + x -= std::floor( x ); + y -= std::floor( y ); + z -= std::floor( z ); // Compute fade curves for each of x, y, z const float u = fade( x ); @@ -143,12 +144,12 @@ float PerlinNoise::noise( float x, float y, float z ) const float PerlinNoise::noise( float x, float y ) const { // Find the unit cube that contains the point - int X = (int) ((float)floor( x )) & 255; - int Y = (int) ((float)floor( y )) & 255; + int X = static_cast( std::floor( x ) ) & 255; + int Y = static_cast( std::floor( y ) ) & 255; // Find relative x, y,z of point in cube - x -= (float)floor( x ); - y -= (float)floor( y ); + x -= std::floor( x ); + y -= std::floor( y ); // Compute fade curves for each of x, y const float u = fade( x ); diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/ray.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/ray.cpp index 5a71041713..c475d93d77 100644 --- a/3d-viewer/3d_rendering/3d_render_raytracing/ray.cpp +++ b/3d-viewer/3d_rendering/3d_render_raytracing/ray.cpp @@ -33,6 +33,8 @@ #include #include +#include + //static unsigned int gs_next_rayID = 0; void RAY::Init( const SFVEC3F& o, const SFVEC3F& d ) @@ -185,7 +187,7 @@ bool IntersectSegment( const SFVEC2F &aStartA, const SFVEC2F &aEnd_minus_startA, aEnd_minus_startB.y - aEnd_minus_startA.y * aEnd_minus_startB.x; - if( fabs(rxs) > glm::epsilon() ) + if( std::abs( rxs ) > glm::epsilon() ) { float inv_rxs = 1.0f / rxs; @@ -294,7 +296,7 @@ bool RAYSEG2D::IntersectSegment( const SFVEC2F &aStart, aEnd_minus_start.y - m_End_minus_start.y * aEnd_minus_start.x; - if( fabs( rxs ) > glm::epsilon() ) + if( std::abs( rxs ) > glm::epsilon() ) { const float inv_rxs = 1.0f / rxs; @@ -371,7 +373,7 @@ bool RAYSEG2D::IntersectCircle( const SFVEC2F &aCenter, // Otherwise check and make sure that the intersections occur on the ray (t // > 0) and return the closer one - const float discriminant = sqrt( discriminantsqr ); + const float discriminant = std::sqrt( discriminantsqr ); const float t1 = (-qd - discriminant); const float t2 = (-qd + discriminant);