Re: Why Java's math expression (power) is so inconvenient and error prone?
- From: Lionel <lionelv_@xxxxxxxxx>
- Date: Tue, 31 Oct 2006 07:26:50 +1000
Shawn wrote:
Hi,
My program need a lot of calculation of power. In many programming
languages,
2**3 = 8;
The syntax is clean and easy. But in Java,
Math.pow(2, 3) = 8; //It is so long, and complicated and error prone
Again, in many languages,
EXP(1) = 2.7 //e value
But in Java,
Math.pow(Math.E, 1) = 2.7 //You see, so complicated
Normally, in one calculation, 2**3 or EXP(3.5) is only part of
expression, like "a + b**3 + EXP(-a)". In Java, it will be very long and
error prone!
Error prone? All the above answers look correct. Can you tell us how it is error prone?
It looks like you have come from C and are expecting non-object-oriented code. Simple, get over it.
If it is so inconvenient then why don't you write a wrapper around the Math class to make things a little easier. For example:
public class MathFunctions {
public static double exp(double someVal) {
return Math.pow(Math.E, someVal);
}
}
Now all you have to do is call MathFunctions.exp(1);
You can shorten the class name if you want.
If that is still too difficult I suggestion you learn about the advantages of an Object-Oriented programming language.
Lionel.
.
- Follow-Ups:
- Re: Why Java's math expression (power) is so inconvenient and error prone?
- From: Ingo Menger
- Re: Why Java's math expression (power) is so inconvenient and error prone?
- From: Arne Vajhøj
- Re: Why Java's math expression (power) is so inconvenient and error prone?
- References:
- Prev by Date: c.l.j.* etiquette/FAQ (WAS: vijaya)
- Next by Date: Re: Java equivalent of C++ Spirit or Boost Graph Library ?
- Previous by thread: Why Java's math expression (power) is so inconvenient and error prone?
- Next by thread: Re: Why Java's math expression (power) is so inconvenient and error prone?
- Index(es):
Relevant Pages
|