mirror of
https://github.com/glfw/glfw.git
synced 2026-07-31 02:37:15 +02:00
Use C99 isfinite instead of various ad-hoc tests
This commit is contained in:
18
src/input.c
18
src/input.c
@@ -333,10 +333,8 @@ void _glfwInputChar(_GLFWwindow* window, uint32_t codepoint, int mods, GLFWbool
|
||||
void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)
|
||||
{
|
||||
assert(window != NULL);
|
||||
assert(xoffset > -FLT_MAX);
|
||||
assert(xoffset < FLT_MAX);
|
||||
assert(yoffset > -FLT_MAX);
|
||||
assert(yoffset < FLT_MAX);
|
||||
assert(isfinite(xoffset));
|
||||
assert(isfinite(yoffset));
|
||||
|
||||
if (window->callbacks.scroll)
|
||||
window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset);
|
||||
@@ -375,10 +373,8 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
|
||||
void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos)
|
||||
{
|
||||
assert(window != NULL);
|
||||
assert(xpos > -FLT_MAX);
|
||||
assert(xpos < FLT_MAX);
|
||||
assert(ypos > -FLT_MAX);
|
||||
assert(ypos < FLT_MAX);
|
||||
assert(isfinite(xpos));
|
||||
assert(isfinite(ypos));
|
||||
|
||||
if (window->virtualCursorPosX == xpos && window->virtualCursorPosY == ypos)
|
||||
return;
|
||||
@@ -436,6 +432,7 @@ void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value)
|
||||
assert(js != NULL);
|
||||
assert(axis >= 0);
|
||||
assert(axis < js->axisCount);
|
||||
assert(isfinite(value));
|
||||
|
||||
js->axes[axis] = value;
|
||||
}
|
||||
@@ -818,8 +815,7 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
assert(window != NULL);
|
||||
|
||||
if (xpos != xpos || xpos < -DBL_MAX || xpos > DBL_MAX ||
|
||||
ypos != ypos || ypos < -DBL_MAX || ypos > DBL_MAX)
|
||||
if (!isfinite(xpos) || !isfinite(ypos))
|
||||
{
|
||||
_glfwInputError(GLFW_INVALID_VALUE,
|
||||
"Invalid cursor position %f %f",
|
||||
@@ -1499,7 +1495,7 @@ GLFWAPI void glfwSetTime(double time)
|
||||
{
|
||||
_GLFW_REQUIRE_INIT();
|
||||
|
||||
if (time != time || time < 0.0 || time > 18446744073.0)
|
||||
if (!isfinite(time) || time < 0.0 || time > 18446744073.0)
|
||||
{
|
||||
_glfwInputError(GLFW_INVALID_VALUE, "Invalid time %f", time);
|
||||
return;
|
||||
|
||||
@@ -467,14 +467,15 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma)
|
||||
unsigned short* values;
|
||||
GLFWgammaramp ramp;
|
||||
const GLFWgammaramp* original;
|
||||
|
||||
assert(gamma > 0.f);
|
||||
assert(gamma <= FLT_MAX);
|
||||
assert(isfinite(gamma));
|
||||
|
||||
_GLFW_REQUIRE_INIT();
|
||||
|
||||
assert(handle != NULL);
|
||||
|
||||
if (gamma != gamma || gamma <= 0.f || gamma > FLT_MAX)
|
||||
if (!isfinite(gamma) || gamma <= 0.f)
|
||||
{
|
||||
_glfwInputError(GLFW_INVALID_VALUE, "Invalid gamma value %f", gamma);
|
||||
return;
|
||||
|
||||
15
src/window.c
15
src/window.c
@@ -32,7 +32,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <float.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW event API //////
|
||||
@@ -135,9 +135,9 @@ void _glfwInputWindowContentScale(_GLFWwindow* window, float xscale, float yscal
|
||||
{
|
||||
assert(window != NULL);
|
||||
assert(xscale > 0.f);
|
||||
assert(xscale < FLT_MAX);
|
||||
assert(isfinite(xscale));
|
||||
assert(yscale > 0.f);
|
||||
assert(yscale < FLT_MAX);
|
||||
assert(isfinite(yscale));
|
||||
|
||||
if (window->callbacks.scale)
|
||||
window->callbacks.scale((GLFWwindow*) window, xscale, yscale);
|
||||
@@ -776,7 +776,7 @@ GLFWAPI float glfwGetWindowOpacity(GLFWwindow* handle)
|
||||
|
||||
GLFWAPI void glfwSetWindowOpacity(GLFWwindow* handle, float opacity)
|
||||
{
|
||||
assert(opacity == opacity);
|
||||
assert(isfinite(opacity));
|
||||
assert(opacity >= 0.f);
|
||||
assert(opacity <= 1.f);
|
||||
|
||||
@@ -785,7 +785,7 @@ GLFWAPI void glfwSetWindowOpacity(GLFWwindow* handle, float opacity)
|
||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||
assert(window != NULL);
|
||||
|
||||
if (opacity != opacity || opacity < 0.f || opacity > 1.f)
|
||||
if (!isfinite(opacity) || opacity < 0.f || opacity > 1.f)
|
||||
{
|
||||
_glfwInputError(GLFW_INVALID_VALUE, "Invalid window opacity %f", opacity);
|
||||
return;
|
||||
@@ -1178,11 +1178,10 @@ GLFWAPI void glfwWaitEvents(void)
|
||||
GLFWAPI void glfwWaitEventsTimeout(double timeout)
|
||||
{
|
||||
_GLFW_REQUIRE_INIT();
|
||||
assert(timeout == timeout);
|
||||
assert(isfinite(timeout));
|
||||
assert(timeout >= 0.0);
|
||||
assert(timeout <= DBL_MAX);
|
||||
|
||||
if (timeout != timeout || timeout < 0.0 || timeout > DBL_MAX)
|
||||
if (!isfinite(timeout) || timeout < 0.0)
|
||||
{
|
||||
_glfwInputError(GLFW_INVALID_VALUE, "Invalid time %f", timeout);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user