Blender
V5.3
intern
cycles
test
util_math_fast_test.cpp
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2024 Blender Foundation
2
*
3
* SPDX-License-Identifier: Apache-2.0 */
4
5
#include <gtest/gtest.h>
6
7
#include "
util/math.h
"
8
#include "
util/math_fast.h
"
9
10
CCL_NAMESPACE_BEGIN
11
12
TEST
(math,
fast_sinf
)
13
{
14
/* Test values in -2PI .. 2PI range. */
15
constexpr
int
N
= 1000 + 1;
16
for
(
int
i = 0; i <
N
; ++i) {
17
const
float
delta = 4 *
M_PI_F
/ (
N
- 1);
18
const
float
phi = -2 *
M_PI_F
+ i * delta;
19
EXPECT_NEAR
(
fast_sinf
(phi),
sinf
(phi), 1.9e-7f);
20
}
21
22
/* Test exact PI/2 values. */
23
EXPECT_NEAR
(
fast_sinf
(
M_PI_2_F
), 1.0f, 1e-9f);
24
EXPECT_NEAR
(
fast_sinf
(-
M_PI_2_F
), -1.0f, 1e-9f);
25
/* Test these close to PI/2 values. */
26
EXPECT_NEAR
(
fast_sinf
(1.57085085f), 0.9999999985f, 1e-9f);
27
EXPECT_NEAR
(
fast_sinf
(-1.57085085f), -0.9999999985f, 1e-9f);
28
29
/* Test large values; fast_sinf expected to do good range reduction. */
30
EXPECT_NEAR
(
fast_sinf
(15378.3f), -0.2025494905f, 2e-4f);
31
EXPECT_NEAR
(
fast_sinf
(-78431.5f), 0.9976474762f, 2e-4f);
32
}
33
34
TEST
(math,
fast_cosf
)
35
{
36
/* Test values in -2PI .. 2PI range. */
37
constexpr
int
N
= 1000 + 1;
38
for
(
int
i = 0; i <
N
; ++i) {
39
const
float
delta = 4 *
M_PI_F
/ (
N
- 1);
40
const
float
phi = -2 *
M_PI_F
+ i * delta;
41
EXPECT_NEAR
(
fast_cosf
(phi),
cosf
(phi), 4.5e-7f);
42
}
43
44
/* Test exact PI/2 values. */
45
EXPECT_NEAR
(
fast_cosf
(
M_PI_2_F
), 0.0f, 3e-7f);
46
EXPECT_NEAR
(
fast_cosf
(-
M_PI_2_F
), 0.0f, 3e-7f);
47
/* Test these close to PI/2 values. */
48
EXPECT_NEAR
(
fast_cosf
(1.57085085f), -0.00005452320508f, 3e-7f);
49
EXPECT_NEAR
(
fast_cosf
(-1.57085085f), -0.00005452320508f, 3e-7f);
50
51
/* Test large values; fast_cosf expected to do good range reduction. */
52
EXPECT_NEAR
(
fast_cosf
(15378.3f), -0.9792720275f, 2e-4f);
53
EXPECT_NEAR
(
fast_cosf
(-78431.5f), 0.06855299586f, 2e-4f);
54
}
55
56
CCL_NAMESPACE_END
M_PI_2_F
#define M_PI_2_F
CCL_NAMESPACE_END
#define CCL_NAMESPACE_END
Definition
device/cuda/compat.h:10
TEST
#define TEST(a, b)
Definition
gpu_shader_test_lib.bsl.hh:209
EXPECT_NEAR
#define EXPECT_NEAR(result, expect, threshold)
Definition
gpu_shader_test_lib.bsl.hh:201
math_fast.h
fast_sinf
ccl_device float fast_sinf(float x)
Definition
math_fast.h:83
fast_cosf
ccl_device float fast_cosf(float x)
Definition
math_fast.h:118
N
#define N
Definition
mball_tessellate.cc:278
CCL_NAMESPACE_BEGIN
Definition
python.cpp:41
sinf
#define sinf
Definition
radial_tiling_shared.hh:84
M_PI_F
#define M_PI_F
Definition
radial_tiling_shared.hh:91
cosf
#define cosf
Definition
radial_tiling_shared.hh:77
math.h
Generated on
for Blender by
doxygen
1.18.0