mirror of
https://github.com/recp/cglm.git
synced 2025-12-25 04:44:58 +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
|
||||
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;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user