From 5d605ce372c7f559f682eb8ab6b3316f251e8c7d Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Jul 2018 10:54:31 +0300 Subject: [PATCH] avoid zero division for percent * two value may be same, in this case now returns 1. * to must be >= from and current <= to && current >= from --- include/cglm/util.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/cglm/util.h b/include/cglm/util.h index d1929f2..34be9b9 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -185,7 +185,12 @@ glm_eq(float a, float b) { CGLM_INLINE float glm_percent(float from, float to, float current) { - return (current - from) / (to - from); + float t; + + if ((t = to - from) == 0.0f) + return 1.0f; + + return (current - from) / t; } /*!