Java Doc for MathUtils.java in  » Science » Apache-commons-math-1.1 » org » apache » commons » math » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » Apache commons math 1.1 » org.apache.commons.math.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.math.util.MathUtils

MathUtils
final public class MathUtils (Code)
Some useful additions to the built-in functions in Math .
version:
   $Revision: 321510 $ $Date: 2005-10-15 15:33:14 -0700 (Sat, 15 Oct 2005) $




Method Summary
public static  intaddAndCheck(int x, int y)
     Add two integers, checking for overflow.
public static  longbinomialCoefficient(int n, int k)
     Returns an exact representation of the Binomial Coefficient, "n choose k", the number of k-element subsets that can be selected from an n-element set.

Preconditions:

  • 0 <= k <= n (otherwise IllegalArgumentException is thrown)
  • The result is small enough to fit into a long.
public static  doublebinomialCoefficientDouble(int n, int k)
     Returns a double representation of the Binomial Coefficient, "n choose k", the number of k-element subsets that can be selected from an n-element set.

Preconditions:

  • 0 <= k <= n (otherwise IllegalArgumentException is thrown)
  • The result is small enough to fit into a double.
public static  doublebinomialCoefficientLog(int n, int k)
     Returns the natural log of the Binomial Coefficient, "n choose k", the number of k-element subsets that can be selected from an n-element set.
public static  doublecosh(double x)
     Returns the hyperbolic cosine of x.
public static  booleanequals(double x, double y)
    
public static  longfactorial(int n)
     Returns n!.
public static  doublefactorialDouble(int n)
     Returns n!.
public static  doublefactorialLog(int n)
     Returns the natural logarithm of n!.
public static  intgcd(int u, int v)
    

Gets the greatest common divisor of the absolute value of two numbers, using the "binary gcd" method which avoids division and modulo operations.

public static  inthash(double value)
     Returns an integer hash code representing the given double value.
public static  byteindicator(byte x)
     For a byte value x, this method returns (byte)(+1) if x >= 0 and (byte)(-1) if x < 0.
public static  doubleindicator(double x)
     For a double precision value x, this method returns +1.0 if x >= 0 and -1.0 if x < 0.
public static  floatindicator(float x)
     For a float value x, this method returns +1.0F if x >= 0 and -1.0F if x < 0.
public static  intindicator(int x)
     For an int value x, this method returns +1 if x >= 0 and -1 if x < 0.
public static  longindicator(long x)
     For a long value x, this method returns +1L if x >= 0 and -1L if x < 0.
public static  shortindicator(short x)
     For a short value x, this method returns (short)(+1) if x >= 0 and (short)(-1) if x < 0.
public static  intlcm(int a, int b)
     Returns the least common multiple between two integer values.
Parameters:
  a - the first integer value.
Parameters:
  b - the second integer value.
public static  intmulAndCheck(int x, int y)
     Multiply two integers, checking for overflow.
public static  doubleround(double x, int scale)
     Round the given value to the specified number of decimal places.
public static  doubleround(double x, int scale, int roundingMethod)
     Round the given value to the specified number of decimal places.
public static  floatround(float x, int scale)
     Round the given value to the specified number of decimal places.
public static  floatround(float x, int scale, int roundingMethod)
     Round the given value to the specified number of decimal places.
public static  bytesign(byte x)
     Returns the sign for byte value x.
public static  doublesign(double x)
     Returns the sign for double precision x.
public static  floatsign(float x)
     Returns the sign for float value x.

For a float value x, this method returns +1.0F if x > 0, 0.0F if x = 0.0F, and -1.0F if x < 0.

public static  intsign(int x)
     Returns the sign for int value x.
public static  longsign(long x)
     Returns the sign for long value x.
public static  shortsign(short x)
     Returns the sign for short value x.
public static  doublesinh(double x)
     Returns the hyperbolic sine of x.
public static  intsubAndCheck(int x, int y)
     Subtract two integers, checking for overflow.



Method Detail
addAndCheck
public static int addAndCheck(int x, int y)(Code)
Add two integers, checking for overflow.
Parameters:
  x - an addend
Parameters:
  y - an addend the sum x+y
throws:
  ArithmeticException - if the result can not be represented as anint
since:
   1.1



binomialCoefficient
public static long binomialCoefficient(int n, int k)(Code)
Returns an exact representation of the Binomial Coefficient, "n choose k", the number of k-element subsets that can be selected from an n-element set.

Preconditions:

  • 0 <= k <= n (otherwise IllegalArgumentException is thrown)
  • The result is small enough to fit into a long. The largest value of n for which all coefficients are < Long.MAX_VALUE is 66. If the computed value exceeds Long.MAX_VALUE an ArithMeticException is thrown.

Parameters:
  n - the size of the set
Parameters:
  k - the size of the subsets to be counted n choose k
throws:
  IllegalArgumentException - if preconditions are not met.
throws:
  ArithmeticException - if the result is too large to be representedby a long integer.



binomialCoefficientDouble
public static double binomialCoefficientDouble(int n, int k)(Code)
Returns a double representation of the Binomial Coefficient, "n choose k", the number of k-element subsets that can be selected from an n-element set.

Preconditions:

  • 0 <= k <= n (otherwise IllegalArgumentException is thrown)
  • The result is small enough to fit into a double. The largest value of n for which all coefficients are < Double.MAX_VALUE is 1029. If the computed value exceeds Double.MAX_VALUE, Double.POSITIVE_INFINITY is returned

Parameters:
  n - the size of the set
Parameters:
  k - the size of the subsets to be counted n choose k
throws:
  IllegalArgumentException - if preconditions are not met.



binomialCoefficientLog
public static double binomialCoefficientLog(int n, int k)(Code)
Returns the natural log of the Binomial Coefficient, "n choose k", the number of k-element subsets that can be selected from an n-element set.

Preconditions:

  • 0 <= k <= n (otherwise IllegalArgumentException is thrown)

Parameters:
  n - the size of the set
Parameters:
  k - the size of the subsets to be counted n choose k
throws:
  IllegalArgumentException - if preconditions are not met.



cosh
public static double cosh(double x)(Code)
Returns the hyperbolic cosine of x.
Parameters:
  x - double value for which to find the hyperbolic cosine hyperbolic cosine of x



equals
public static boolean equals(double x, double y)(Code)
Returns true iff both arguments are NaN or neither is NaN and they are equal
Parameters:
  x - first value
Parameters:
  y - second value true if the values are equal or both are NaN



factorial
public static long factorial(int n)(Code)
Returns n!. Shorthand for n Factorial, the product of the numbers 1,...,n.

Preconditions:

  • n >= 0 (otherwise IllegalArgumentException is thrown)
  • The result is small enough to fit into a long. The largest value of n for which n! < Long.MAX_VALUE is 20. If the computed value exceeds Long.MAX_VALUE an ArithMeticException is thrown.


Parameters:
  n - argument n!
throws:
  ArithmeticException - if the result is too large to be representedby a long integer.
throws:
  IllegalArgumentException - if n < 0



factorialDouble
public static double factorialDouble(int n)(Code)
Returns n!. Shorthand for n Factorial, the product of the numbers 1,...,n as a double.

Preconditions:

  • n >= 0 (otherwise IllegalArgumentException is thrown)
  • The result is small enough to fit into a double. The largest value of n for which n! < Double.MAX_VALUE is 170. If the computed value exceeds Double.MAX_VALUE, Double.POSITIVE_INFINITY is returned


Parameters:
  n - argument n!
throws:
  IllegalArgumentException - if n < 0



factorialLog
public static double factorialLog(int n)(Code)
Returns the natural logarithm of n!.

Preconditions:

  • n >= 0 (otherwise IllegalArgumentException is thrown)

Parameters:
  n - argument n!
throws:
  IllegalArgumentException - if preconditions are not met.



gcd
public static int gcd(int u, int v)(Code)

Gets the greatest common divisor of the absolute value of two numbers, using the "binary gcd" method which avoids division and modulo operations. See Knuth 4.5.2 algorithm B. This algorithm is due to Josef Stein (1961).


Parameters:
  u - a non-zero number
Parameters:
  v - a non-zero number the greatest common divisor, never zero
since:
   1.1



hash
public static int hash(double value)(Code)
Returns an integer hash code representing the given double value.
Parameters:
  value - the value to be hashed the hash code



indicator
public static byte indicator(byte x)(Code)
For a byte value x, this method returns (byte)(+1) if x >= 0 and (byte)(-1) if x < 0.
Parameters:
  x - the value, a byte (byte)(+1) or (byte)(-1), depending on the sign of x



indicator
public static double indicator(double x)(Code)
For a double precision value x, this method returns +1.0 if x >= 0 and -1.0 if x < 0. Returns NaN if x is NaN.
Parameters:
  x - the value, a double +1.0 or -1.0, depending on the sign of x



indicator
public static float indicator(float x)(Code)
For a float value x, this method returns +1.0F if x >= 0 and -1.0F if x < 0. Returns NaN if x is NaN.
Parameters:
  x - the value, a float +1.0F or -1.0F, depending on the sign of x



indicator
public static int indicator(int x)(Code)
For an int value x, this method returns +1 if x >= 0 and -1 if x < 0.
Parameters:
  x - the value, an int +1 or -1, depending on the sign of x



indicator
public static long indicator(long x)(Code)
For a long value x, this method returns +1L if x >= 0 and -1L if x < 0.
Parameters:
  x - the value, a long +1L or -1L, depending on the sign of x



indicator
public static short indicator(short x)(Code)
For a short value x, this method returns (short)(+1) if x >= 0 and (short)(-1) if x < 0.
Parameters:
  x - the value, a short (short)(+1) or (short)(-1), depending on the sign of x



lcm
public static int lcm(int a, int b)(Code)
Returns the least common multiple between two integer values.
Parameters:
  a - the first integer value.
Parameters:
  b - the second integer value. the least common multiple between a and b.
throws:
  ArithmeticException - if the lcm is too large to store as an int
since:
   1.1



mulAndCheck
public static int mulAndCheck(int x, int y)(Code)
Multiply two integers, checking for overflow.
Parameters:
  x - a factor
Parameters:
  y - a factor the product x*y
throws:
  ArithmeticException - if the result can not be represented as anint
since:
   1.1



round
public static double round(double x, int scale)(Code)
Round the given value to the specified number of decimal places. The value is rounded using the BigDecimal.ROUND_HALF_UP method.
Parameters:
  x - the value to round.
Parameters:
  scale - the number of digits to the right of the decimal point. the rounded value.
since:
   1.1



round
public static double round(double x, int scale, int roundingMethod)(Code)
Round the given value to the specified number of decimal places. The value is rounded using the given method which is any method defined in BigDecimal .
Parameters:
  x - the value to round.
Parameters:
  scale - the number of digits to the right of the decimal point.
Parameters:
  roundingMethod - the rounding method as defined inBigDecimal. the rounded value.
since:
   1.1



round
public static float round(float x, int scale)(Code)
Round the given value to the specified number of decimal places. The value is rounding using the BigDecimal.ROUND_HALF_UP method.
Parameters:
  x - the value to round.
Parameters:
  scale - the number of digits to the right of the decimal point. the rounded value.
since:
   1.1



round
public static float round(float x, int scale, int roundingMethod)(Code)
Round the given value to the specified number of decimal places. The value is rounded using the given method which is any method defined in BigDecimal .
Parameters:
  x - the value to round.
Parameters:
  scale - the number of digits to the right of the decimal point.
Parameters:
  roundingMethod - the rounding method as defined inBigDecimal. the rounded value.
since:
   1.1



sign
public static byte sign(byte x)(Code)
Returns the sign for byte value x.

For a byte value x, this method returns (byte)(+1) if x > 0, (byte)(0) if x = 0, and (byte)(-1) if x < 0.
Parameters:
  x - the value, a byte (byte)(+1), (byte)(0), or (byte)(-1), depending on the sign of x




sign
public static double sign(double x)(Code)
Returns the sign for double precision x.

For a double value x, this method returns +1.0 if x > 0, 0.0 if x = 0.0, and -1.0 if x < 0. Returns NaN if x is NaN.
Parameters:
  x - the value, a double +1.0, 0.0, or -1.0, depending on the sign of x




sign
public static float sign(float x)(Code)
Returns the sign for float value x.

For a float value x, this method returns +1.0F if x > 0, 0.0F if x = 0.0F, and -1.0F if x < 0. Returns NaN if x is NaN.
Parameters:
  x - the value, a float +1.0F, 0.0F, or -1.0F, depending on the sign of x




sign
public static int sign(int x)(Code)
Returns the sign for int value x.

For an int value x, this method returns +1 if x > 0, 0 if x = 0, and -1 if x < 0.
Parameters:
  x - the value, an int +1, 0, or -1, depending on the sign of x




sign
public static long sign(long x)(Code)
Returns the sign for long value x.

For a long value x, this method returns +1L if x > 0, 0L if x = 0, and -1L if x < 0.
Parameters:
  x - the value, a long +1L, 0L, or -1L, depending on the sign of x




sign
public static short sign(short x)(Code)
Returns the sign for short value x.

For a short value x, this method returns (short)(+1) if x > 0, (short)(0) if x = 0, and (short)(-1) if x < 0.
Parameters:
  x - the value, a short (short)(+1), (short)(0), or (short)(-1), depending on the sign ofx




sinh
public static double sinh(double x)(Code)
Returns the hyperbolic sine of x.
Parameters:
  x - double value for which to find the hyperbolic sine hyperbolic sine of x



subAndCheck
public static int subAndCheck(int x, int y)(Code)
Subtract two integers, checking for overflow.
Parameters:
  x - the minuend
Parameters:
  y - the subtrahend the difference x-y
throws:
  ArithmeticException - if the result can not be represented as anint
since:
   1.1



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.