• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DOUBLE_EQ(a, b)                                             \
21     do {                                                                   \
22         if (!(fabs(a - b) < DBL_EPSILON))                                  \
23             t_error("%s failed: %f is not equal to %f\n", __func__, a, b); \
24     } while (0)
25 
26 /*
27  * @tc.name      : significand_0100
28  * @tc.desc      : Get mantissa of floating-point number 0.0
29  * @tc.level     : Level 0
30  */
significand_0100(void)31 void significand_0100(void)
32 {
33     double d = significand(0.0);
34     EXPECT_DOUBLE_EQ(0.0, d);
35 }
36 
37 /*
38  * @tc.name      : significand_0200
39  * @tc.desc      : Get mantissa of floating-point number 1.2
40  * @tc.level     : Level 1
41  */
significand_0200(void)42 void significand_0200(void)
43 {
44     double d = significand(1.2);
45     EXPECT_DOUBLE_EQ(1.2, d);
46 }
47 
48 /*
49  * @tc.name      : significand_0300
50  * @tc.desc      : Get mantissa of floating-point number 12.25
51  * @tc.level     : Level 1
52  */
significand_0300(void)53 void significand_0300(void)
54 {
55     double d = significand(12.25);
56     EXPECT_DOUBLE_EQ(1.53125, d);
57 }
58 
main(int argc,char * argv[])59 int main(int argc, char *argv[])
60 {
61     significand_0100();
62     significand_0200();
63     significand_0300();
64     return t_status;
65 }