xref: /aosp_15_r20/system/media/audio_utils/tests/audio_float_tests.cpp (revision b9df5ad1c9ac98a7fefaac271a55f7ae3db05414)
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <audio_utils/float_test_utils.h>
18 #include <gtest/gtest.h>
19 
TEST(audio_float_tests,Basic)20 TEST(audio_float_tests, Basic) {
21     // Precision test for the CPU.
22     // The ARM does subnormals but the x86-64 does not under fast-math.
23     //
24     // single precision float
25     EXPECT_EQ(127, android::audio_utils::test::test_max_exponent<float>());
26 
27     // -126 is expected if subnormals are not implemented,
28     // the value will be less than that if subnormals are implemented.
29     EXPECT_LE(android::audio_utils::test::test_min_exponent<float>(), -126);
30 
31     EXPECT_EQ(23, android::audio_utils::test::test_mantissa<float>());
32 
33     // double precision float
34     EXPECT_EQ(1023, android::audio_utils::test::test_max_exponent<double>());
35 
36     // -1022 is expected if subnormals are not implemented,
37     // the value will be less than that if subnormals are implemented.
38     EXPECT_LE(android::audio_utils::test::test_min_exponent<double>(), -1022);
39 
40     EXPECT_EQ(52, android::audio_utils::test::test_mantissa<double>());
41 }
42