Repository: godotengine/godot
File: core/math/math_funcs.h (C/C++)

Code before:

	// These methods assume (p_num + p_den) doesn't overflow.
	static _ALWAYS_INLINE_ int32_t division_round_up(int32_t p_num, int32_t p_den) {
		int32_t offset = (p_num < 0 && p_den < 0) ? 1 : -1;
		return (p_num + p_den + offset) / p_den;
	}
	static _ALWAYS_INLINE_ uint32_t division_round_up(uint32_t p_num, uint32_t p_den) {
		return (p_num + p_den - 1) / p_den;
	}
	static _ALWAYS_INLINE_ int64_t division_round_up(int64_t p_num, int64_t p_den) {
		int32_t offset = (p_num < 0 && p_den < 0) ? 1 : -1;
		return (p_num + p_den + offset) / p_den;
	}
	static _ALWAYS_INLINE_ uint64_t division_round_up(uint64_t p_num, uint64_t p_den) {
		return (p_num + p_den - 1) / p_den;
	}

	static _ALWAYS_INLINE_ bool is_finite(double p_val) { return isfinite(p_val); }
	static _ALWAYS_INLINE_ bool is_finite(float p_val) { return isfinite(p_val); }

	static _ALWAYS_INLINE_ double abs(double g) { return absd(g); }
	static _ALWAYS_INLINE_ float abs(float g) { return absf(g); }
	static _ALWAYS_INLINE_ int8_t abs(int8_t g) { return g > 0 ? g : -g; }
	static _ALWAYS_INLINE_ int16_t abs(int16_t g) { return g > 0 ? g : -g; }
	static _ALWAYS_INLINE_ int32_t abs(int32_t g) { return ::abs(g); }
	static _ALWAYS_INLINE_ int64_t abs(int64_t g) { return ::abs(g); }

	static _ALWAYS_INLINE_ double fposmod(double p_x, double p_y) {
		double value = Math::fmod(p_x, p_y);
		if (((value < 0) && (p_y > 0)) || ((value > 0) && (p_y < 0))) {
			value += p_y;
		}
		value += 0.0;
		return value;
	}
	static _ALWAYS_INLINE_ float fposmod(float p_x, float p_y) {
		float value = Math::fmod(p_x, p_y);
		if (((value < 0) && (p_y > 0)) || ((value > 0) && (p_y < 0))) {
			value += p_y;
		}
		value += 0.0f;
		return value;
	}
	static _ALWAYS_INLINE_ float fposmodp(float p_x, float p_y) {
		float value = Math::fmod(p_x, p_y);
		if (value < 0) {
			value += p_y;
		}
		value += 0.0f;
		return value;
	}

Review comment (suggestion):
```suggestion
	static _ALWAYS_INLINE_ int64_t abs(int64_t g) { return ::labs(g); }
```

Careful, I'm not sure if `abs(long)` is guaranteed to exist: https://en.cppreference.com/w/c/numeric/math/abs

Code after:

	// These methods assume (p_num + p_den) doesn't overflow.
	static _ALWAYS_INLINE_ int32_t division_round_up(int32_t p_num, int32_t p_den) {
		int32_t offset = (p_num < 0 && p_den < 0) ? 1 : -1;
		return (p_num + p_den + offset) / p_den;
	}
	static _ALWAYS_INLINE_ uint32_t division_round_up(uint32_t p_num, uint32_t p_den) {
		return (p_num + p_den - 1) / p_den;
	}
	static _ALWAYS_INLINE_ int64_t division_round_up(int64_t p_num, int64_t p_den) {
		int32_t offset = (p_num < 0 && p_den < 0) ? 1 : -1;
		return (p_num + p_den + offset) / p_den;
	}
	static _ALWAYS_INLINE_ uint64_t division_round_up(uint64_t p_num, uint64_t p_den) {
		return (p_num + p_den - 1) / p_den;
	}

	static _ALWAYS_INLINE_ bool is_finite(double p_val) { return isfinite(p_val); }
	static _ALWAYS_INLINE_ bool is_finite(float p_val) { return isfinite(p_val); }

	static _ALWAYS_INLINE_ double abs(double g) { return absd(g); }
	static _ALWAYS_INLINE_ float abs(float g) { return absf(g); }
	static _ALWAYS_INLINE_ int8_t abs(int8_t g) { return g > 0 ? g : -g; }
	static _ALWAYS_INLINE_ int16_t abs(int16_t g) { return g > 0 ? g : -g; }
	static _ALWAYS_INLINE_ int32_t abs(int32_t g) { return ::abs(g); }
	static _ALWAYS_INLINE_ int64_t abs(int64_t g) { return ::llabs(g); }

	static _ALWAYS_INLINE_ double fposmod(double p_x, double p_y) {
		double value = Math::fmod(p_x, p_y);
		if (((value < 0) && (p_y > 0)) || ((value > 0) && (p_y < 0))) {
			value += p_y;
		}
		value += 0.0;
		return value;
	}
	static _ALWAYS_INLINE_ float fposmod(float p_x, float p_y) {
		float value = Math::fmod(p_x, p_y);
		if (((value < 0) && (p_y > 0)) || ((value > 0) && (p_y < 0))) {
			value += p_y;
		}
		value += 0.0f;
		return value;
	}
	static _ALWAYS_INLINE_ float fposmodp(float p_x, float p_y) {
		float value = Math::fmod(p_x, p_y);
		if (value < 0) {
			value += p_y;
		}
		value += 0.0f;
		return value;
	}