Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / MathExtension.java @ 40561

History | View | Annotate | Download (3.44 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.utils;
25
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
26
 *
27
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
28
 *
29
 * This program is free software; you can redistribute it and/or
30
 * modify it under the terms of the GNU General Public License
31
 * as published by the Free Software Foundation; either version 2
32
 * of the License, or (at your option) any later version.
33
 *
34
 * This program is distributed in the hope that it will be useful,
35
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
 * GNU General Public License for more details.
38
 *
39
 * You should have received a copy of the GNU General Public License
40
 * along with this program; if not, write to the Free Software
41
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
42
 *
43
 * For more information, contact:
44
 *
45
 *  Generalitat Valenciana
46
 *   Conselleria d'Infraestructures i Transport
47
 *   Av. Blasco Ib??ez, 50
48
 *   46010 VALENCIA
49
 *   SPAIN
50
 *
51
 *      +34 963862235
52
 *   gvsig@gva.es
53
 *      www.gvsig.gva.es
54
 *
55
 *    or
56
 *
57
 *   IVER T.I. S.A
58
 *   Salamanca 50
59
 *   46005 Valencia
60
 *   Spain
61
 *
62
 *   +34 963163400
63
 *   dac@iver.es
64
 */
65

    
66
/**
67
 * Some more mathematical functions that 'java.lang.Math' doesn't have:
68
 * - Logarithm operations: log2, log2Integer, logX, logXInteger
69
 * 
70
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
71
 */
72
public final class MathExtension {
73
        
74
        /**
75
         * 2-base logarithm of a
76
         * @param a The value to do the calculations
77
         * @return Logarithm in 2 base of 'a'
78
         */
79
        public static double log2(double a) {
80
                return (Math.log(a) / Math.log(2));
81
        }
82
        
83
        /**
84
         * 2-base logarithm of a, but the result doesn't have decimals (approximated to the integer number most near by below)
85
         * @param a The value to do the calculations
86
         * @return Logarithm in 2 base of 'a', as an integer
87
         */
88
        public static int log2Integer(double a) {
89
                return (int) Math.floor(log2(a));
90
        }
91
        
92
        /**
93
         * X-base logarithm of a
94
         * @param a The value to do the calculations
95
         * @return Logarithm in X base of 'a'
96
         */
97
        public static double logX(double x_base, double a) {
98
                return (Math.log(a) / Math.log(x_base));
99
        }
100
        
101
        /**
102
         * X-base logarithm of a, but the result doesn't have decimals (approximated to the integer number most near by below)
103
         * @param a The value to do the calculations
104
         * @return Logarithm in X base of 'a', as an integer
105
         */
106
        public static int logXInteger(double x_base, double a) {
107
                return (int) Math.floor(logX(x_base, a));
108
        }
109
}