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;

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.
.



Relevant Pages

  • Re: Head-in-the-Sand Liberals (LA Times Columnist)
    ... You claimed to have known several computer languages, ... If you lie about knowing computer languages, ... of the programming loop for a functional ... You also don't know Java. ...
    (rec.org.mensa)
  • Re: How come Ada isnt more popular?
    ... Most programming languages were terrible at that time, ... And we talked about "Why isn't Ada more popular?". ... Adopting Java ...
    (comp.lang.ada)
  • Re: performance question
    ... that let me mix different programming styles more freely. ... When I started learning Java, my biggest problem was that I ... I've noticed that people often prefer to take shortcuts when writing code - ... deficiencies in the model and/or the existing languages that implement ...
    (comp.lang.java.programmer)
  • Re: Bloody Java again
    ... I passed my Java exams last year but really have ... Erlang's concurrent programming is rather abstract and high-level. ... He is not being asked to grade umpteenth different languages. ... Student: "It's all in the program, ...
    (comp.lang.functional)
  • Re: Static vs. Dynamic typing (big advantage or not)---WAS: c.programming: OOP and memory management
    ... >>A few years ago I started learning Smalltalk. ... >>features in alternative languages. ... > know that there is widespread ignorance about programming language features ... eiffel developers even though the type system in eiffel is superior to Java. ...
    (comp.programming)