1/*
2 * Copyright (C) 2012 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 "math_entrypoints.h"
18
19#include <limits>
20
21#include "common_runtime_test.h"
22
23namespace art {
24
25class MathEntrypointsTest : public CommonRuntimeTest {};
26
27TEST_F(MathEntrypointsTest, DoubleToLong) {
28  EXPECT_EQ(std::numeric_limits<int64_t>::max(), art_d2l(1.85e19));
29  EXPECT_EQ(std::numeric_limits<int64_t>::min(), art_d2l(-1.85e19));
30  EXPECT_EQ(INT64_C(0), art_d2l(0));
31  EXPECT_EQ(INT64_C(1), art_d2l(1.0));
32  EXPECT_EQ(INT64_C(10), art_d2l(10.0));
33  EXPECT_EQ(INT64_C(100), art_d2l(100.0));
34  EXPECT_EQ(INT64_C(-1), art_d2l(-1.0));
35  EXPECT_EQ(INT64_C(-10), art_d2l(-10.0));
36  EXPECT_EQ(INT64_C(-100), art_d2l(-100.0));
37}
38
39TEST_F(MathEntrypointsTest, FloatToLong) {
40  EXPECT_EQ(std::numeric_limits<int64_t>::max(), art_f2l(1.85e19));
41  EXPECT_EQ(std::numeric_limits<int64_t>::min(), art_f2l(-1.85e19));
42  EXPECT_EQ(INT64_C(0), art_f2l(0));
43  EXPECT_EQ(INT64_C(1), art_f2l(1.0));
44  EXPECT_EQ(INT64_C(10), art_f2l(10.0));
45  EXPECT_EQ(INT64_C(100), art_f2l(100.0));
46  EXPECT_EQ(INT64_C(-1), art_f2l(-1.0));
47  EXPECT_EQ(INT64_C(-10), art_f2l(-10.0));
48  EXPECT_EQ(INT64_C(-100), art_f2l(-100.0));
49}
50
51TEST_F(MathEntrypointsTest, DoubleToInt) {
52  EXPECT_EQ(std::numeric_limits<int32_t>::max(), art_d2i(4.3e9));
53  EXPECT_EQ(std::numeric_limits<int32_t>::min(), art_d2i(-4.3e9));
54  EXPECT_EQ(0L, art_d2i(0));
55  EXPECT_EQ(1L, art_d2i(1.0));
56  EXPECT_EQ(10L, art_d2i(10.0));
57  EXPECT_EQ(100L, art_d2i(100.0));
58  EXPECT_EQ(-1L, art_d2i(-1.0));
59  EXPECT_EQ(-10L, art_d2i(-10.0));
60  EXPECT_EQ(-100L, art_d2i(-100.0));
61}
62
63TEST_F(MathEntrypointsTest, FloatToInt) {
64  EXPECT_EQ(std::numeric_limits<int32_t>::max(), art_f2i(4.3e9));
65  EXPECT_EQ(std::numeric_limits<int32_t>::min(), art_f2i(-4.3e9));
66  EXPECT_EQ(0L, art_f2i(0));
67  EXPECT_EQ(1L, art_f2i(1.0));
68  EXPECT_EQ(10L, art_f2i(10.0));
69  EXPECT_EQ(100L, art_f2i(100.0));
70  EXPECT_EQ(-1L, art_f2i(-1.0));
71  EXPECT_EQ(-10L, art_f2i(-10.0));
72  EXPECT_EQ(-100L, art_f2i(-100.0));
73}
74
75}  // namespace art
76