1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.numbers.examples.jmh.arrays;
18
19 /**
20 * Support class for double math.
21 *
22 * @since 1.2
23 */
24 final class DoubleMath {
25 /** No instances. */
26 private DoubleMath() {}
27
28 /**
29 * Return {@code true} if {@code x > y}.
30 *
31 * <p>Respects the sort ordering of {@link Double#compare(double, double)}:
32 *
33 * <pre>{@code
34 * Double.compare(x, y) > 0
35 * }</pre>
36 *
37 * @param x Value.
38 * @param y Value.
39 * @return {@code x > y}
40 */
41 static boolean greaterThan(double x, double y) {
42 if (x > y) {
43 return true;
44 }
45 if (x < y) {
46 return false;
47 }
48 // Equal numbers; signed zeros (-0.0, 0.0); or NaNs
49 final long a = Double.doubleToLongBits(x);
50 final long b = Double.doubleToLongBits(y);
51 return a > b;
52 }
53
54 /**
55 * Return {@code true} if {@code x < y}.
56 *
57 * <p>Respects the sort ordering of {@link Double#compare(double, double)}:
58 *
59 * <pre>{@code
60 * Double.compare(x, y) < 0
61 * }</pre>
62 *
63 * @param x Value.
64 * @param y Value.
65 * @return {@code x < y}
66 */
67 static boolean lessThan(double x, double y) {
68 if (x < y) {
69 return true;
70 }
71 if (x > y) {
72 return false;
73 }
74 // Equal numbers; signed zeros (-0.0, 0.0); or NaNs
75 final long a = Double.doubleToLongBits(x);
76 final long b = Double.doubleToLongBits(y);
77 return a < b;
78 }
79 }