blob: f70a2da2f571fb356ba1b8965515a9d6a5b12ce5 [file] [log] [blame]
Logan Chien008fa512012-06-22 08:09:57 -07001/*
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
Ian Rogers7655f292013-07-29 11:07:13 -070017#include "math_entrypoints.h"
Logan Chien008fa512012-06-22 08:09:57 -070018
Logan Chien008fa512012-06-22 08:09:57 -070019#include <limits>
20
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080021#include "common_runtime_test.h"
22
Logan Chien008fa512012-06-22 08:09:57 -070023namespace art {
24
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080025class MathEntrypointsTest : public CommonRuntimeTest {};
Logan Chien008fa512012-06-22 08:09:57 -070026
Ian Rogers7655f292013-07-29 11:07:13 -070027TEST_F(MathEntrypointsTest, DoubleToLong) {
Logan Chien008fa512012-06-22 08:09:57 -070028 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));
Ian Rogers0f678472014-03-10 16:18:37 -070030 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));
Logan Chien008fa512012-06-22 08:09:57 -070037}
38
Ian Rogers7655f292013-07-29 11:07:13 -070039TEST_F(MathEntrypointsTest, FloatToLong) {
Logan Chien008fa512012-06-22 08:09:57 -070040 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));
Ian Rogers0f678472014-03-10 16:18:37 -070042 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));
Logan Chien008fa512012-06-22 08:09:57 -070049}
50
Ian Rogers7655f292013-07-29 11:07:13 -070051TEST_F(MathEntrypointsTest, DoubleToInt) {
Logan Chien008fa512012-06-22 08:09:57 -070052 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
Ian Rogers7655f292013-07-29 11:07:13 -070063TEST_F(MathEntrypointsTest, FloatToInt) {
Logan Chien008fa512012-06-22 08:09:57 -070064 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