Math.pow versus multiply for squaring

Does anyone know which is faster for squaring doubles? Using math.pow to raise the value to the power of two, or to simply multiply the value by itself.
thanks.
-Brian

^ As was my ill-advised original response to the @OP. :D

Similar Messages

  • Is using Math.pow faster than multiplying myself?

    Hi all,
    Is it faster to use Math.pow to calculate a power than to, say, multiply it myself in a loop? How about if I'm just doing a square -- is it faster to use Math.pow(x,2) than x * x?
    I noticed that the pow method in StrictMath has the keyword "native." Does this mean it's being done by the operating system? Does it mean it's being done directly in the hardware?
    Thanks!
    Tim

    TimQuinn wrote:
    This is in an inner-loop deep in a simulation, so I'd like it to be as fast as possible. From the above, I'm gathering that I should keep using pow for my ^8 calculation, but substitute a simple multiplication for my ^2 calculation.Not necessarily. Remember that N^8 = ((N^2)^2)^2. The Math.pow algorithm will very likely use this optimization, but you can too.
    Related question: does it make any difference at all in these kinds of operations if I use floats or doubles? In terms of speed, I mean, not precision.Actual answer to all of your questions: try all of the possibilities in your simulation and see what actually happens.

  • Math power function in script logic

    Hello all!
    Can anybody help me how  I can do math "power" function in BPC 5.1 Script Logic?
    Thanks

    Let's say you have a source account FOO and you want to calculate FOO to the 5th power, posting the result to FOOFIVE.
    In BPC SQL scripting, there are no mathematical functions to play with (powers, roots, sine, cosine, etc.) except for add, subtract, multiply and divide -- plus you can round results in your Factor or Expression. So that means, we must use multiplication.
    You could certainly do this using a bunch of intermediate accounts, one each for foo squared, foo cubed, foo to the 4th, and foo to the 5th. That would require *GO in between each *WHEN/REC block, and could be slow.
    I haven't tried this, but I think this should work, all in one statement:
    *XDIM_ACCOUNT = FOO
    *WHEN *
    *IS *
    REC(Factor=GET(Account="FOO")GET(Account="FOO")GET(Account="FOO")GET(Account="FOO")*GET(Account="FOO"),Account=FOOFIVE)
    *ENDWHEN
    If you want FOO to the 50th power, copy & paste.
    If you want square root of FOO, that could be a real challenge. I think to use straight BPC SQL logic it wouldn't be possible. I would probably write a stored procedure using SQL's SQRT(), and call that from the BPC logic file. Likewise for any other geometric functions, complex algebra, etc.
    There also may be a way to calculate powers in MDX -- that's more mathematically straightforward -- but as a BPC on MS person, I really never ever use MDX due to performance.
    Regards,
    Tim

  • X^2 to Math.pow(x,2)

    I am writing a program that takes an argument equation and calculates a Riemann sum. I've got the bulk of the coding written. I have no problem converting any type of trig functions in the argument to their proper string representations of the java.lang.Math class and method, ie if user enters sin(x)/cos(x), the program converts it to a string of Math.sin(x)/Math.cos(x). However, when I try to convert x^2 (x squared) to Math.pow(x,2), the computer just leaves it as it is. This is the code i've tried so far:
    args[0] = sin(x)/cos(x)  // user input at command line
    args[0].replaceAll("sin","Math\u002Esin");
    args[0].replaceAll("cos","Math\u002Esin");However, when I try the same with x^2 as input, even with the unicode instead of a carat, the output is still just x^2. Any idea how I can get a string of x^2 converted to Math.pow(x,2) ?

    then you're going to need a regular expression
    something
    like.replaceAll("(.*)x\\^([0-9]).*(.*)", "\\1
    Math.pow(x, \\2) \\3")
    Solved the problem with
    for(int i = 0; i < 10000; i++){
       s = s.replaceAll(String.format("x\\^"+i),String.format("Math\u002Epow("+i+")") );
    }covers integer exponents up to 10000, and barely noticeable increase in calculation time. thanks to all for the help!

  • How do you calculate a (base * power) sans math.pow?

    I've been tasked with trying to figure out how to do an exponent question without using the math.pow(3,2) method. How would I do that?

    Yeah it's a non negative number but I don't
    understand how a loop would complete this.Say you want to find the value of 10^5, you just do:
    int product = 1;
    product *= 10; // this is the same as product = product  * 10
    product *= 10;
    product *= 10;
    product *= 10;
    product *= 10; Use a for statement for this:
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html

  • Forcing server VM not to optimise Math.pow ?

    Deep in my system I have a set of libraries for which I don't have the source and which I have been unsuccessful in decompiling. The problem is that these libraries call Math.pow and Math.exp, which are defined in terms of allowed uncertainity in the results.
    Unfortunately, my application requires strict reproducibility in its results, so this is a little irritating :( Is there any way to force the server VM (I'm using JDK 1.5.0_03 under RH Linux FC3) not to take advantage of its optimisations for the java.lang.Math class? I would like it to optimise everything else that it can, but not the operations that are defined in terms of ulp (Math.pow, Math.exp, Math.sin, etc.).
    As I mentioned, it is not possible for me to replace the calls to java.lang.Math with calls to java.lang.StrictMath (although I have done this where it is possible). I guess I'm looking for a VM flag that will allow me to do this.
    Thanks in advance,
    R

    I haven't worked in this area, but was curious of the answer myself....
    This is an old reference, but I think it's still valid...
    Do a search for "strictfp".
    At quick glance, it looks like you can prefix your class or interface declaration with "strictfp" and it uses the strict math version.
    Eg.
    class strictfp MyClass
      // blah blah...
    }http://java.sun.com/developer/JDCTechTips/2001/tt0410.html#using
    regards,
    Owen

  • Confuzed about Math.pow

    Hello all its me again -_-
    I have a simple question, I am trying to get an algorithm to function like this :
    15000 ( 0.07/ 12 )
    -36
    (1 - ( 1 + 0.07 / 12 ) )
    where the -36 is the -36th power
    I have tried this:
    answer = (15000 * (.07 / 12)) / (1 - ( 1 + 0.07 / 12 ) * Math.pow(-36));
    but alas i get this error message :
    exam5.java:14: pow(double,double) in java.lang.Math cannot be applied to (int)
    answer = (15000 * (.07 / 12)) / (1 - ( 1 + 0.07 / 12 ) * Math.pow(-36));
    I do not understand this because the answer is a double and i have to int data types in this problem O_0
    So the question is:
    How can I fix my algorithm to function like the one I posted at the beginning, or how would I go about writing an algorithm like that.
    your regards
    Drag

    Oops just noticed that when I posted the algorithm it was
    15000 ( 0.07/ 12 )
    36
    (1 - ( 1 + 0.07 / 12 ) )
    where the -36 is the -36th power
    it is supossed to be
    15000 ( 0.07/ 12 )
    -----------------------> -36
    (1 - ( 1 + 0.07 / 12 ) )
    where the -36 is the -36th power
    and it is between the closing two parentheses
    very sorry , that is probably why your suggestion did give me the answer I was looking for
    Your Regards,
    Drag

  • Math.pow

    Hi all, I've got a simple question:
    4 to the power of 29 is 288230376151711744.
    The following results in 288230376151711740 though.
    double t=Math.pow(4,29);
    Why? (Writing your own pow-method naturally solves the problem, but what's happening here?)

    For instance:
        public static void main(String[] args)
            BigInteger myBigInt = new BigInteger("4");
            BigInteger resultBigInt = myBigInt.pow(29);
            double resultDbl = resultBigInt.doubleValue();
            System.out.println("BigInteger Result:  " + resultBigInt.toString());
            System.out.println("Double Result:      " + String.valueOf(resultDbl));
        }

  • Math.pow problem

    Hello guys, I trying to get math.pow of specific value but it returns me unusual ouput which i don't understand. Here is the formula
    Math.pow(3333.625, 2));
    Output:
    1.1113055640625E7
    when i used google to compute it here is the result
    Result:
    11 113 055.6
    I also notice the E7 in the end of the value. Can any help undertand what is it and how can i convert it into normal output like in google. Thank for your time.

    Use java.math.BigDecimal.
    Here's a sample
    import java.math.*;
    public class MathPow
         public static void main(String args[])
              //System.out.println( Math.pow(3333.625, 2) );
              BigDecimal bd = new BigDecimal(Math.pow(3333.625, 2));
              System.out.println(bd.toString());
    }

  • Math.pow(Math.E, time)

    Hi folks!
    The expression
    "Math.pow( Math.E, time )" keeps giving me a "divide by zero" error.
    This seems to be similar to problems others have had, but the other solutions don't quite work in my case, since Math.E isn't negative.  "time" of course is a non-integer, but the expression doesn't even work for me if I replace it with "Math.ceil(time)." 
    Can anybody tell me what I'm missing?  Thanks in advance!
    --S

    Thanks for the reply!
    My original expression was
    thet = time;
    a = 2;
    b = 0.5;
    exp = Math.pow(Math.E, b*thet);
    posx = a*exp*Math.cos(thet);
    posy = a*exp*Math.sin(thet);
    [640, 640] + [posx, posy]
    except that a and b were slider values.  If I use Math.exp,
    thet = time;
    a = 2;
    b = 0.5;
    exp = Math.exp(b*thet);
    posx = a*exp*Math.cos(thet);
    posy = a*exp*Math.sin(thet);
    [640, 640] + [posx, posy]
    I get the same error.  I found a work-around by attaching theta to a slider instead, but I'm still curious to know what the problem was.
    Thanks again!
    --S

  • Math.pow in MIDP

    Is Math.pow supported in MIDP ?
    If not, what to use instead ?
    Thanks.

    Is Math.pow supported in MIDP ?{color:#000080}No.{color}
    If not, what to use instead ?{color:#000080}Roll your own, if you can't find anything on the net. I would start by examining the j2se source for the method, and if it doesn't involve calls to other methods I would adopt it.
    Just be sure whatever you write or adopt can run in the limited capability of a mobile device :-)
    db{color}

  • On line banking for another person, my Mom, who I have power of attorney for heard ppffzzzttt while inputting Mom's sensitive id info in while trying to log in again? I've had the iPad 3/ 4 & 4.5 and never heard this sound before.

    I tried to access my Mother's bank for online banking. She has had a slow decline with dementia, I'm Power Of Attorney for her. When not being able to sign in, I heard through the iPad 4 Wi-fi 64 gig, a measured buzz sound, like ppffzzzttt. I've had 3  / 4 &amp; 4.5 and never heard this sound before.
    I have had Power of Attorney for my Mom for quite some time. She has been suffering with dementia in a slow then sped up type after her last heart attack. I was the worst candidate for the job but no one else would take it.
    I set up banking on line so I could pay her bills. I am disabled and have trouble paying my own. The iPad again filled those shoes perfectly.
    I logged on yesterday, and the page said, user name not found. I figured it might have been server maintenance or poor typing but even with all personal details the server would not send my user name.
    I became concerned because today I received the Vudu letter that said their headquarters were broken into on March 25th, 2013, and a number of hard drives were stolen with all info they keep on me. They set up an all clear id free of charge for a year, if I wanted to take advantage of it which I did.
    The part that bothers me is when I was inputting my Mother's  sensitive id information my iPad 4 / Wi-Fi / 64 gig emitted a measured buzz sound 3 times. I have had the 3 / 4 / 4.5 / faster processor but did not go for the 128 gig 4.75, and in all that time I have never heard that sound.
    The question, was the bank computer or the FBI probing my iPad 4 and did it place something on it in the memory or damage it in anyway.
    I was on the phone for the next three hours with the good, bad and ugly at Citizens. After talking to an acquaintance bank manager who said she saw no problem and did not know why I could not log in. I spent the next three hours on the phone and ended up talking to a nasty tech who said, it was a rule that I could not do my Mother's banking on line anymore. A "rule" prevented me from acting in that manner. It all, from every party sounded so "hinky," Don Johnson, Miami Vice and wondered if there was a rule at all.
    I asked him why and what triggered the on line banking system to suddenly boot me? The fact I had set it up about one year ago to date and it has performed flawlessly since that time and a whole year later it flagged the account. He said it could have been anything, pressing the wrong key, etc. I knew he was getting edgy so I ended up getting off the line with him because nothing would be accomplished.
    I would appreciate any and all speculations, ideas, or suggestions as I look over banking law, rules, in the next few days. By the way, the money we are talking about is miniscule. A small SS check and an even smaller pension check.
    Thank you,
    halfcack

    That situation went from inconvenient to complicated quickly.  Wait for any pending orders to drop off, wait for things to clear up, wait till your upgrade comes up and then upgrade when your contract is fulfilled.  I would have suggested a replacement phone, I know, with only a month left why couldn't you just upgrade early, but these situations where people try to upgrade early always end horribly and once a phone order starts, it almost cannot finish until something winds up shipped received and returned.  Sorry this happened the way it did.  Definitely not efficient.

  • Can you charge a macbook by any other means than the power cord? For example the usb drive? My cord works fine but the outlet on the laptop is not.

    Can you charge a macbook by any other means than the power cord? For example the usb drive? My cord works fine but the outlet on the laptop is not.

    The only way to charge a MBP is with a MagSafe power supply (wall or airline) try http://support.apple.com/kb/TS1713

  • Does anyone know the power cord part for HP A532 printer? I need a replacement cord. THANKS!

    Does anyone know the power cord part for HP A532 printer? I need a replacement cord. THANKS!

    Here's the steps to follow if your printer isn't turning on.   
    If you've gone through all those steps and you still don't have power, there are a lot of places that sell a replacement cord and supply for that printer. 
    I am an HP employee.

  • I'm traveling to London for the summer, does anyone know a good power adapter/converter for my MacBook Pro?

    I'm traveling to London for the summer, does anyone know a good power adapter/converter for my MacBook Pro? I know there's the Travel Adapter Kit but it's only for iPhones, iPods, iPad, etc.

    Apple World Travel Adapter Kit
    The World Travel Adapter Kit includes the Apple USB Power Adapter, USB Cable and six interchangeable AC adapter plugs for use with iPod, iPhone, and iPad. The adapter plugs can also be used with Apple MagSafe Power Adapters, Portable Power Adapters, and AirPort Express, so you can plug your power adapter into most electrical outlets around the world.
    Copied from the Apple Store: http://store.apple.com/uk/product/MB974ZM/B?fnode=MTY1NDEwMQ&mco=MTA4NDE3MDQ

Maybe you are looking for

  • How to restrict data from tables in a view cluster

    Hi, I have 5 Z* tables, Company code is the common code in all of these. I have created a view cluster on these five tables. My requirement is to viewcluster should display the data of the user's company code. When i see the data in SE54 it is showin

  • [JS CS2/3] where can i download ESTK 2

    I've written a script meant for ID CS2 on a PC on a mac in CS3, and now i need to do some platform specific debugging, so i need to run ESTK2 on Windows, but i can't find a download anywhere... UPDATE: OK, found it (looked at the Bridge SDK and there

  • Spool number and program name

    Hi All, Im trying to fetch spool number based on object name(program name). The table TSP01 has the field RQ2NAME has the program name in it, with some additional characters. For example, if the program name is ZQRR1234 , its showing it as ZQRR1234_A

  • What port number to use with NTRealm

    When I configured the NTRealm in the WLS console, the documentation mentioned that for NT Domain, I was supposed to provide the "name" and "port" values for the PDC machine. I gave the name of the machine on that field, but did not know what to speci

  • Problem in adding the new column in VO : ADF

    Hi, I am using jdev 10.1.3.2 with ADF. I added a new column in a table in the database. In my ADF application, I right clicked on the entity object of the changed table, and selected 'Synchronize with DB' which added the new column in the entity obje