Blender V5.0
util_math_float3_test.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2025 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5/* Note: These fixtures test default micro-architecture optimization defined in the
6 * util/optimization.h. */
7
8#include <gtest/gtest.h>
9
10#include "util/math.h"
11
13
14class Float3Test : public ::testing::Test {
15 void SetUp() override
16 {
17 /* The micro-architecture check is not needed here, but use it here as a demonstration of how
18 * it can be implemented in a clear way. */
19 // GTEST_SKIP() << "Test skipped due to uarch capability";
20 }
21};
22
24{
25 {
26 const float3 c = fmod(make_float3(1.2f, 2.3f, 3.4f), 1.0f);
27 EXPECT_NEAR(c.x, 0.2f, 1e-6f);
28 EXPECT_NEAR(c.y, 0.3f, 1e-6f);
29 EXPECT_NEAR(c.z, 0.4f, 1e-6f);
30 }
31
32 {
33 const float3 c = fmod(make_float3(1.2f, 2.3f, 3.4f), 1.2f);
34 EXPECT_NEAR(c.x, 0.0f, 1e-6f);
35 EXPECT_NEAR(c.y, 1.1f, 1e-6f);
36 EXPECT_NEAR(c.z, 1.0f, 1e-6f);
37 }
38
39 {
40 const float3 c = fmod(make_float3(1.2f, 2.3f, 3.4f), 1000000.0f);
41 EXPECT_NEAR(c.x, 1.2f, 1e-6f);
42 EXPECT_NEAR(c.y, 2.3f, 1e-6f);
43 EXPECT_NEAR(c.z, 3.4f, 1e-6f);
44 }
45
46 {
47 const float3 c = fmod(make_float3(1999999.2f, 2000000.3f, 2000001.4f), 1000000.0f);
48 EXPECT_NEAR(c.x, 999999.25f, 1e-6f);
49 EXPECT_NEAR(c.y, 0.25f, 1e-6f);
50 EXPECT_NEAR(c.z, 1.375f, 1e-6f);
51 }
52
53 {
54 const float3 c = fmod(make_float3(5.1f, -5.1f, 0.0f), 3.0f);
55 EXPECT_NEAR(c.x, 2.1f, 1e-6f);
56 EXPECT_NEAR(c.y, -2.1, 1e-6f);
57 EXPECT_NEAR(c.z, 0.0f, 1e-6f);
58 }
59
60 {
61 const float3 c = fmod(make_float3(5.1f, -5.1f, 0.0f), -3.0f);
62 EXPECT_NEAR(c.x, 2.1f, 1e-6f);
63 EXPECT_NEAR(c.y, -2.1, 1e-6f);
64 }
65}
66
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
ccl_device_inline float2 fmod(const float2 a, const float b)
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
TEST_F(Float3Test, fmod)