Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/math_base_inline.c
| Show First 20 Lines • Show All 350 Lines • ▼ Show 20 Lines | |||||
| MINLINE int divide_floor_i(int a, int b) | MINLINE int divide_floor_i(int a, int b) | ||||
| { | { | ||||
| int d = a / b; | int d = a / b; | ||||
| int r = a % b; /* Optimizes into a single division. */ | int r = a % b; /* Optimizes into a single division. */ | ||||
| return r ? d - ((a < 0) ^ (b < 0)) : d; | return r ? d - ((a < 0) ^ (b < 0)) : d; | ||||
| } | } | ||||
| /** | /** | ||||
| * Integer division that ceils the result, instead of flooring like normal C division. | |||||
| */ | |||||
| MINLINE uint divide_ceil_u(uint a, uint b) | |||||
Severin: Fails to compile here on Apple Clang, because of undefined type `uint`. I had to include… | |||||
JacquesLuckeAuthorUnsubmitted Done Inline ActionsI made it unsigned, because I was too lazy to find a version that works correctly for negative and positive numbers. Also, I don't a case where this behavior would be useful for negative values. JacquesLucke: I made it unsigned, because I was too lazy to find a version that works correctly for negative… | |||||
| { | |||||
| return (a + b - 1) / b; | |||||
| } | |||||
| /** | |||||
| * modulo that handles negative numbers, works the same as Python's. | * modulo that handles negative numbers, works the same as Python's. | ||||
| */ | */ | ||||
| MINLINE int mod_i(int i, int n) | MINLINE int mod_i(int i, int n) | ||||
| { | { | ||||
| return (i % n + n) % n; | return (i % n + n) % n; | ||||
| } | } | ||||
| MINLINE float fractf(float a) | MINLINE float fractf(float a) | ||||
| ▲ Show 20 Lines • Show All 430 Lines • Show Last 20 Lines | |||||
Fails to compile here on Apple Clang, because of undefined type uint. I had to include "BLI_sys_types.h".
Why is this using unsigned anyway? There are probably plenty of hidden bugs in Blender because of unsigned-signed comparisons, and I know Sergey is quite against using them too.