Skip to content

Commit

Permalink
Fix InvSqrt causing nans
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn committed Dec 22, 2023
1 parent 85f5543 commit 197b578
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/FastNoise/Generators/Modifiers.inl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ class FastSIMD::DispatchClass<FastNoise::SquareRoot, SIMD> final : public virtua
{
float32v value = this->GetSourceValue( mSource, seed, pos... );

return FS::InvSqrt( FS::Max( FS::Abs( value ), float32v( FLT_MIN ) ) ) * value;
float32v invSqrt = FS::InvSqrt( FS::Abs( value ) );

return FS::Masked( invSqrt != float32v( INFINITY ), value * invSqrt );
}
};

Expand Down
4 changes: 3 additions & 1 deletion include/FastNoise/Generators/Utils.inl
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ namespace FastNoise
float32v distSqr = dX * dX;
((distSqr = FS::FMulAdd( d, d, distSqr )), ...);

return FS::InvSqrt( distSqr ) * distSqr;
float32v invSqrt = FS::InvSqrt( distSqr );

return FS::Masked( invSqrt != float32v( INFINITY ), distSqr * invSqrt );
}

case DistanceFunction::EuclideanSquared:
Expand Down

0 comments on commit 197b578

Please sign in to comment.