1 // Copyright 2025 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 // This tests the target platform's C standard library version of logf.
16 //
17 // Note: We have caught real production bugs with these tests. This exercises
18 // accelerated FPU operations.
19 #include <array>
20 #include <cmath>
21
22 #include "pw_unit_test/framework.h"
23
24 namespace pw {
25 namespace {
26
TEST(logf,BasicOne)27 TEST(logf, BasicOne) { EXPECT_FLOAT_EQ(logf(1.0f), 0.0f); }
28
TEST(logf,BasicE)29 TEST(logf, BasicE) { EXPECT_FLOAT_EQ(logf(expf(1.0f)), 1.0f); }
30
TEST(logf,Array)31 TEST(logf, Array) {
32 std::array<float, 8> sequence{{
33 14.3f,
34 25.1f,
35 46.4f,
36 78.9f,
37 14.3f,
38 25.1f,
39 46.4f,
40 78.9f,
41 }};
42 std::array<float, 8> expected{{
43 2.6602595372658615f,
44 3.2228678461377385f,
45 3.8372994592322094f,
46 4.368181227851829f,
47 2.6602595372658615f,
48 3.2228678461377385f,
49 3.8372994592322094f,
50 4.368181227851829f,
51 }};
52 for (size_t i = 0; i < sequence.size(); i++) {
53 EXPECT_FLOAT_EQ(logf(sequence[i]), expected[i]);
54 }
55 }
56
57 } // namespace
58 } // namespace pw
59