blob: ca8b9313091ae4f73b936facb7c5e872986f441a [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
19#include "common_test.h"
20#include <limits>
21
22namespace art {
23
Ian Rogers7655f292013-07-29 11:07:13 -070024class MathEntrypointsTest : public CommonTest {};
Logan Chien008fa512012-06-22 08:09:57 -070025
Ian Rogers7655f292013-07-29 11:07:13 -070026TEST_F(MathEntrypointsTest, DoubleToLong) {
Logan Chien008fa512012-06-22 08:09:57 -070027 EXPECT_EQ(std::numeric_limits<int64_t>::max(), art_d2l(1.85e19));
28 EXPECT_EQ(std::numeric_limits<int64_t>::min(), art_d2l(-1.85e19));
29 EXPECT_EQ(0LL, art_d2l(0));
30 EXPECT_EQ(1LL, art_d2l(1.0));
31 EXPECT_EQ(10LL, art_d2l(10.0));
32 EXPECT_EQ(100LL, art_d2l(100.0));
33 EXPECT_EQ(-1LL, art_d2l(-1.0));
34 EXPECT_EQ(-10LL, art_d2l(-10.0));
35 EXPECT_EQ(-100LL, art_d2l(-100.0));
36}
37
Ian Rogers7655f292013-07-29 11:07:13 -070038TEST_F(MathEntrypointsTest, FloatToLong) {
Logan Chien008fa512012-06-22 08:09:57 -070039 EXPECT_EQ(std::numeric_limits<int64_t>::max(), art_f2l(1.85e19));
40 EXPECT_EQ(std::numeric_limits<int64_t>::min(), art_f2l(-1.85e19));
41 EXPECT_EQ(0LL, art_f2l(0));
42 EXPECT_EQ(1LL, art_f2l(1.0));
43 EXPECT_EQ(10LL, art_f2l(10.0));
44 EXPECT_EQ(100LL, art_f2l(100.0));
45 EXPECT_EQ(-1LL, art_f2l(-1.0));
46 EXPECT_EQ(-10LL, art_f2l(-10.0));
47 EXPECT_EQ(-100LL, art_f2l(-100.0));
48}
49
Ian Rogers7655f292013-07-29 11:07:13 -070050TEST_F(MathEntrypointsTest, DoubleToInt) {
Logan Chien008fa512012-06-22 08:09:57 -070051 EXPECT_EQ(std::numeric_limits<int32_t>::max(), art_d2i(4.3e9));
52 EXPECT_EQ(std::numeric_limits<int32_t>::min(), art_d2i(-4.3e9));
53 EXPECT_EQ(0L, art_d2i(0));
54 EXPECT_EQ(1L, art_d2i(1.0));
55 EXPECT_EQ(10L, art_d2i(10.0));
56 EXPECT_EQ(100L, art_d2i(100.0));
57 EXPECT_EQ(-1L, art_d2i(-1.0));
58 EXPECT_EQ(-10L, art_d2i(-10.0));
59 EXPECT_EQ(-100L, art_d2i(-100.0));
60}
61
Ian Rogers7655f292013-07-29 11:07:13 -070062TEST_F(MathEntrypointsTest, FloatToInt) {
Logan Chien008fa512012-06-22 08:09:57 -070063 EXPECT_EQ(std::numeric_limits<int32_t>::max(), art_f2i(4.3e9));
64 EXPECT_EQ(std::numeric_limits<int32_t>::min(), art_f2i(-4.3e9));
65 EXPECT_EQ(0L, art_f2i(0));
66 EXPECT_EQ(1L, art_f2i(1.0));
67 EXPECT_EQ(10L, art_f2i(10.0));
68 EXPECT_EQ(100L, art_f2i(100.0));
69 EXPECT_EQ(-1L, art_f2i(-1.0));
70 EXPECT_EQ(-10L, art_f2i(-10.0));
71 EXPECT_EQ(-100L, art_f2i(-100.0));
72}
73
74} // namespace art