Re: Why Java's math expression (power) is so inconvenient and error prone?



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


.



Relevant Pages

  • Re: objects (newbie)
    ... Programming languages such as Java and C++ are object-oriented ... that can be applied in recurring software ... Design Patterns - Elements of Object-Oriented Software ...
    (comp.lang.java.help)
  • Re: size_t problems
    ... In Java, an int is a 32 bit signed value. ... other programming languages get by just fine ... The way to minimize the pain of writing 100% portable code is to write ...
    (comp.lang.c)
  • Re: Should I learn C before Java ?
    ... Should I jump right into Java, or is it better to learn ... You're right about JavaScript and Java being completely different ... whatever opinions you have on programming languages. ... discharging that responsibility. ...
    (comp.lang.java.programmer)
  • Re: JVM based languages? (mildly OT)
    ... there are other programming languages that can run in a Java Virtual ... including the z/OS Java SDK (and also in application environments ... that support Java, such as CICS Transaction Server, IMS Transaction ...
    (bit.listserv.ibm-main)
  • Re: creating licenses for my own demos?
    ... Both Java and JavaScript support a wide variety of code ... dangerous as programming languages than Macro-32 is. ... So while I trust myself on point 1 above, if I cannot even trust myself ...
    (comp.os.vms)