2 * Copyright 2008 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "include/core/SkScalar.h"
9 #include "include/private/SkFixed.h"
10 #include "include/private/SkFloatBits.h"
11 #include "include/private/SkFloatingPoint.h"
12 #include "src/core/SkMathPriv.h"
13 #include "src/core/SkSafeMath.h"
15 ///////////////////////////////////////////////////////////////////////////////
17 /* www.worldserver.com/turk/computergraphics/FixedSqrt.pdf
19 int32_t SkSqrtBits(int32_t x, int count) {
20 SkASSERT(x >= 0 && count > 0 && (unsigned)count <= 30);
29 remHi = (remHi<<2) | (remLo>>30);
32 uint32_t testDiv = (root << 1) + 1;
33 if (remHi >= testDiv) {
37 } while (--count >= 0);
42 ///////////////////////////////////////////////////////////////////////////////////////////////////
44 size_t SkSafeMath::Add(size_t x, size_t y) {
46 size_t sum = tmp.add(x, y);
47 return tmp.ok() ? sum : SIZE_MAX;
50 size_t SkSafeMath::Mul(size_t x, size_t y) {
52 size_t prod = tmp.mul(x, y);
53 return tmp.ok() ? prod : SIZE_MAX;
56 ///////////////////////////////////////////////////////////////////////////////////////////////////
58 bool sk_floats_are_unit(const float array[], size_t count) {
60 for (size_t i = 0; i < count; ++i) {
61 is_unit &= (array[i] >= 0) & (array[i] <= 1);