From e47731f1e5ad9efac5edf36dde7f7e7bcb026496 Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Fri, 15 May 2020 22:31:27 +0200 Subject: [PATCH] sanitized square roots --- include/gp/math.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/gp/math.hpp b/include/gp/math.hpp index 8a0910b..9d5661e 100644 --- a/include/gp/math.hpp +++ b/include/gp/math.hpp @@ -13,9 +13,14 @@ namespace gp { T lerp(T input, T low, T high) { return low + (high - low) * input; } + template + T lextrap(T input, T low, T high) { + return (input - low) / (high - low); + } template T fixed_sqrt(T value) { + gp_config::assertion(value >= 0, "trying to compute square root of negative number"); if(value == 0) return 0; T ret = value / 2; T tmp; @@ -30,6 +35,7 @@ namespace gp { template T epsilon_sqrt(T value) { + gp_config::assertion(value >= 0, "trying to compute square root of negative number"); if(value == 0) return 0; T ret = value / 2; T tmp; @@ -52,6 +58,7 @@ namespace gp { template T stable_sqrt(T value) { + gp_config::assertion(value >= 0, "trying to compute square root of negative number"); if(value == 0) return 0; T ret = value / 2; T tmp;