Fix type promotion in math function

This commit is contained in:
Camille 2017-09-24 13:06:10 +02:00 committed by Wayne Stambaugh
parent 9ff66a5274
commit 5c4f8abd24
2 changed files with 16 additions and 13 deletions

View File

@ -40,6 +40,7 @@
*/
#include "PerlinNoise.h"
#include <cmath>
#include <iostream>
#include <cmath>
#include <random>
@ -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<int>( std::floor( x ) ) & 255;
int Y = static_cast<int>( std::floor( y ) ) & 255;
int Z = static_cast<int>( 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<int>( std::floor( x ) ) & 255;
int Y = static_cast<int>( 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 );

View File

@ -33,6 +33,8 @@
#include <stdio.h>
#include <wx/debug.h>
#include <cmath>
//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<float>() )
if( std::abs( rxs ) > glm::epsilon<float>() )
{
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<float>() )
if( std::abs( rxs ) > glm::epsilon<float>() )
{
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);