0

I am working on an exponents method for a program I am working on but I am having difficulties with the IEEE 745 approximation standard.

Originally I used Math.pow( ) but noticed that the Java.Math doesn't address the IEEE 745 approximation.

My question is, is there a method or class that processes exponential powers and addresses IEEE 745?

  • 1
    IEEE-754 is a *floating-point standard*. Can you expand on and clarify what you mean by "I used Math.pow( ) but noticed that the Java.Math doesn't address the IEEE 745 approximation"? What have you tried (relevant code would be good), what results did you get, and what did you expect instead? The question is unclear in its present form. – njuffa Apr 06 '17 at 15:02
  • For example Math.pow(0.1, 2) = 0.010000000000000002. When the expected value is 0.01. Even though the difference is so insignificant, I need the actual mathematical value of 0.01. My question is has someone created a solution to return the expected mathematical value for exponents. (I am looking for a solution similar to the solution for adding currencies in java to avoid the same error that Math.pow( ) can return based on the IEEE 754 standard) – Max Williams Apr 06 '17 at 15:44
  • 1
    [BigDecimal](http://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html)? – VGR Apr 06 '17 at 16:25
  • "For example Math.pow(0.1, 2) = 0.010000000000000002." Fundamental problem: 0.1 is not exactly representable in binary floating-point formats (see this [question](http://stackoverflow.com/questions/588004/is-floating-point-math-broken)). Try decimal arithmetic (also standardized by IEEE-754). An additional issue can be that mathematical functions, as implemented in math libraries, don't typically return correctly rounded results in the sense of IEEE-754. – njuffa Apr 06 '17 at 16:42
  • 2
    Possible duplicate of [Is floating point math broken?](http://stackoverflow.com/questions/588004/is-floating-point-math-broken) – beaker Apr 06 '17 at 19:18
  • @njuffa thats the problem I am having. I was just inquiring to see if someone else has already created solutions to this problem for exponents or if I will have to write the code myself. – Max Williams Apr 06 '17 at 19:27
  • @MaxWilliams You may want to look into BigDecimal as suggested by VGR. – njuffa Apr 06 '17 at 19:33
  • @beaker similar but no. That thread is just about the Floating point approximation. Where this is looking for a specific solution to exponents as decimal arithmetic doesn't work as nicely for exponents as it does for addition, subtraction, multiplication, and division. – Max Williams Apr 06 '17 at 20:57
  • @VGR I must have read over that. I will look into it to see if it is a possible solution – Max Williams Apr 06 '17 at 20:58
  • @VGR The class BigDecimal is not a valid solution because it only allows precision to a point which is not what I am trying to do. – Max Williams Apr 07 '17 at 18:06
  • It would certainly work for squaring 0.1. Can you provide an example of some math where, say, a million digits is not sufficient? – VGR Apr 07 '17 at 18:32
  • Its not so much 1 specific value but its the fact that with the approximation when the value is used multiple times the error compounds and eventually will return values that are inaccurate. – Max Williams Apr 08 '17 at 01:31
  • I was able to figure it out through brute force. Now onto radicals... – Max Williams Apr 17 '17 at 21:58
  • If anyone has ideas on how to do this please feel free to help out its a mess. – Max Williams Apr 17 '17 at 21:59

0 Answers0