Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 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 | |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 17 | #include "math_entrypoints.h" |
Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 18 | |
Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 19 | #include <limits> |
| 20 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 21 | #include "common_runtime_test.h" |
| 22 | |
Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 23 | namespace art { |
| 24 | |
Brian Carlstrom | a1ce1fe | 2014-02-24 23:23:58 -0800 | [diff] [blame] | 25 | class MathEntrypointsTest : public CommonRuntimeTest {}; |
Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 26 | |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 27 | TEST_F(MathEntrypointsTest, DoubleToLong) { |
Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 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)); |
Ian Rogers | 0f67847 | 2014-03-10 16:18:37 -0700 | [diff] [blame] | 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)); |
Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 39 | TEST_F(MathEntrypointsTest, FloatToLong) { |
Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 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)); |
Ian Rogers | 0f67847 | 2014-03-10 16:18:37 -0700 | [diff] [blame] | 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)); |
Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 51 | TEST_F(MathEntrypointsTest, DoubleToInt) { |
Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 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 | |
Ian Rogers | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 63 | TEST_F(MathEntrypointsTest, FloatToInt) { |
Logan Chien | 008fa51 | 2012-06-22 08:09:57 -0700 | [diff] [blame] | 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 |