forked from openize-com/openize-heic-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathUtils.java
More file actions
85 lines (80 loc) · 2.08 KB
/
Copy pathMathUtils.java
File metadata and controls
85 lines (80 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Openize.HEIC
* Copyright (c) 2024-2025 Openize Pty Ltd.
*
* This file is part of Openize.HEIC.
*
* Openize.HEIC is available under Openize license, which is
* available along with Openize.HEIC sources.
*/
package openize;
/**
* <p>
* Provides additional mathematics methods.
* </p>
*/
public final class MathUtils
{
/**
* <p>
* Returns the natural logarithm (base {@code newBase}) of a double value.
* </p>
* @param value a value
* @param newBase a base
* @return the value of ln(value), the natural logarithm of value.
*/
public static double log(double value, double newBase)
{
if (newBase == 1.0)
{
return Double.NaN;
}
else
{
double result = Math.log(value) / Math.log(newBase);
return result == 0.0 ? 0.0 : result;
}
}
/**
* Returns the smallest (closest to negative infinity)
* {@code double} value that is greater than or equal to the
* argument and is equal to a mathematical integer.
*
*
* @param value a value.
* @return the smallest (closest to negative infinity)
* floating-point value that is greater than or equal to
* the argument and is equal to a mathematical integer.
*/
public static double ceiling(double value)
{
if (!Double.isInfinite(value) && !Double.isNaN(value))
{
double result = Math.floor(value);
if (result != value)
{
++result;
}
return result;
}
else
{
return value;
}
}
/**
* <p>
* Converts the double value to int.
* </p>
* @param doubleValue The double value.
* @return The int value.
*/
public static int f64_s32(double doubleValue)
{
return (doubleValue == doubleValue
&& !(doubleValue < -2.147483647E9)
&& !(doubleValue > 2.147483647E9))
? (int) doubleValue
: Integer.MIN_VALUE;
}
}