Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/core/math_utils.h
- This file was moved from extern/draco/dracoenc/src/draco/core/math_utils.h.
| Show All 21 Lines | |||||
| #define DRACO_INCREMENT_MOD(I, M) (((I) == ((M)-1)) ? 0 : ((I) + 1)) | #define DRACO_INCREMENT_MOD(I, M) (((I) == ((M)-1)) ? 0 : ((I) + 1)) | ||||
| // Returns floor(sqrt(x)) where x is an integer number. The main intend of this | // Returns floor(sqrt(x)) where x is an integer number. The main intend of this | ||||
| // function is to provide a cross platform and deterministic implementation of | // function is to provide a cross platform and deterministic implementation of | ||||
| // square root for integer numbers. This function is not intended to be a | // square root for integer numbers. This function is not intended to be a | ||||
| // replacement for std::sqrt() for general cases. IntSqrt is in fact about 3X | // replacement for std::sqrt() for general cases. IntSqrt is in fact about 3X | ||||
| // slower compared to most implementation of std::sqrt(). | // slower compared to most implementation of std::sqrt(). | ||||
| inline uint64_t IntSqrt(uint64_t number) { | inline uint64_t IntSqrt(uint64_t number) { | ||||
| if (number == 0) | if (number == 0) { | ||||
| return 0; | return 0; | ||||
| } | |||||
| // First estimate good initial value of the square root as log2(number). | // First estimate good initial value of the square root as log2(number). | ||||
| uint64_t act_number = number; | uint64_t act_number = number; | ||||
| uint64_t square_root = 1; | uint64_t square_root = 1; | ||||
| while (act_number >= 2) { | while (act_number >= 2) { | ||||
| // Double the square root until |square_root * square_root > number|. | // Double the square root until |square_root * square_root > number|. | ||||
| square_root *= 2; | square_root *= 2; | ||||
| act_number /= 4; | act_number /= 4; | ||||
| } | } | ||||
| Show All 15 Lines | |||||