mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
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:
@@ -185,7 +185,12 @@ glm_eq(float a, float b) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
float
|
float
|
||||||
glm_percent(float from, float to, float current) {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
Reference in New Issue
Block a user