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
This commit is contained in:
Recep Aslantas
2018-07-10 10:54:31 +03:00
parent c216c0cb7e
commit 5d605ce372

View File

@@ -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;
}
/*!