Re: Why Java's math expression (power) is so inconvenient and error prone?
- From: Mark Thornton <mark.p.thornton@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 30 Oct 2006 19:43:28 GMT
Shawn wrote:
Hi,
My program need a lot of calculation of power. In many programming languages,
2**3 = 8; //or
2^3 = 8;
That may be short but your example illustrates the problem: lack of a universal standard symbol (in ascii). Of course 2^3 already means something else in Java.
The syntax is clean and easy. But in Java,
Math.pow(2, 3) = 8; //It is so long, and complicated and error prone
It may be longer but not error prone. You can eliminate the repeated use of Math with static import:
import static java.lang.Math.*
then
pow(2,3)
Again, in many languages,
EXP(1) = 2.7 //e value
But in Java,
Math.pow(Math.E, 1) = 2.7 //You see, so complicated
Math.exp(1)
or with a static import, just
exp(1)
Mark Thornton
.
- References:
- Prev by Date: Re: Servlet to JSP problem
- Next by Date: Re: J2ME WTK: Developing for differnent cell phones
- 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
|