0

enter image description here

I have these formulas and I'm looking for a way to translate them into code, but I chew more that I could eat, I really don't know how to raise a value to a fractional power in programming.

I stumbled with these questions:

But they don't answer my question

So... what's the proper way to do that?

EDIT:

SHOOT!!

I thought if I ask a simple question with less info I could get a proper answer...

Well... here is my attempt to do what I want to do:

If I follow the answer from the first question I get this:

public static void main(String []args)
     {
         double pow = 3.0/2;
         double valA = 20.5;
         System.out.println(Math.pow(valA, pow)/(6 * Math.sqrt(Math.PI)));
     }

Result: 8.727796365331747

If I do like I was doing:

public static void main(String []args)
     {
         double pow = 3/2;
         double valA = 20.5;
         System.out.println(Math.pow(valA, pow)/(6 * Math.sqrt(Math.PI)));
     }

Result: 1.9276477437881674

Again... What's the proper way? and why?

Community
  • 1
  • 1
NAYIR55
  • 105
  • 5
  • 17
  • How does [this](http://stackoverflow.com/questions/29877030/raising-number-to-fractional-power-java) not answer your question? It in fact *is* the answer. – Hovercraft Full Of Eels Sep 30 '16 at 22:16
  • If you still need help, you need to show your attempt to use this information (essentially `Math.pow(...)`) and tell us more about how it's not working for you. – Hovercraft Full Of Eels Sep 30 '16 at 22:17
  • @NAYIR55 like the post linked by Hovercraft, when you have an operation by two integers the result will be an integer, even if the result would be a fraction. The value will be truncate. The different result on your examples is because on your first example you are using a double value (3.0) which produces a double result. The correct way depends of what your doing and how you want the number to be treated, as double or integer. – Victor Bello Sep 30 '16 at 23:37
  • I can not answer my own question because it is marked as a duplicate even though I said I found a question already answered – NAYIR55 Oct 01 '16 at 00:00
  • When calculating `pow=3/2` this is treated as integer division and the result is rounded down to 1. – Salix alba Oct 01 '16 at 01:44

0 Answers0