1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://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,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <float.h>
17 #include <math.h>
18 #include "test.h"
19
20 #define EXPECT_FLOAT_EQ(a, b) \
21 do { \
22 if (!(fabsf(a - b) < FLT_EPSILON)) \
23 t_error("%s failed: %f is not equal to %f\n", __func__, a, b); \
24 } while (0)
25
26 /*
27 * @tc.name : significandf_0100
28 * @tc.desc : Get mantissa of floating-point number 0.0f
29 * @tc.level : Level 0
30 */
significandf_0100(void)31 void significandf_0100(void)
32 {
33 float f = significandf(0.0f);
34 EXPECT_FLOAT_EQ(0.0f, f);
35 }
36
37 /*
38 * @tc.name : significandf_0200
39 * @tc.desc : Get mantissa of floating-point number 1.2f
40 * @tc.level : Level 1
41 */
significandf_0200(void)42 void significandf_0200(void)
43 {
44 float f = significandf(1.2f);
45 EXPECT_FLOAT_EQ(1.2f, f);
46 }
47
48 /*
49 * @tc.name : significandf_0300
50 * @tc.desc : Get mantissa of floating-point number 12.25f
51 * @tc.level : Level 1
52 */
significandf_0300(void)53 void significandf_0300(void)
54 {
55 float f = significandf(12.25f);
56 EXPECT_FLOAT_EQ(1.53125f, f);
57 }
58
main(int argc,char * argv[])59 int main(int argc, char *argv[])
60 {
61 significandf_0100();
62 significandf_0200();
63 significandf_0300();
64 return t_status;
65 }