The whole number of points of the offer-value of the sword

Source: Internet
Author: User

Title Description

The integer exponent of the floating-point base and int type given a double type. The exponent of the base of the second party.

/*** Consider the situation: The index may be positive, negative, 0. * Base is 0, exponent is 0 or negative, throw exception handling *@paramBase Radix *@paramExponent Index *@return     */     Public Static DoublePowerDoubleBaseintexponent) {        //The index and the base cannot be 0 at the same time, mathematically meaningless .        if(Equal (base, 0.0) && exponent <= 0)            Throw NewRuntimeException ("Invalid iuput. Base and exponent both is zero "); //index is 0, return 1        if(Exponent = = 0)            return1.0; intExp =exponent; if(Exponent < 0) Exp= -exp; //seeking power to the square        Doubleresult =powerwithunsignedexponent (base, exp); //The exponent is negative and the countdown is        if(Exponent < 0) {result= 1.0/result; }                returnresult; }    Private Static DoublePowerwithunsignedexponent (DoubleBaseintexp) {        Doubleresult = 1.0;  for(intI=1; i<=exp; i++) {result*=Base; }        returnresult; }        //Comparison of two double type data    Private Static BooleanEqualDoubleNUM1,Doublenum2) {        if((Num1-num2 > -0.0000001) && (Num1-num2 < 0.0000001))             return true; return false; }

Optimization method:

Private Static DoublePowerWithUnsignedExponent1 (DoubleBaseintexp) {        if(exp = = 0)            return1.0; if(exp = = 1)            returnBase; Doubleresult = Powerwithunsignedexponent (base, exp >> 1);//shift right instead of dividing by 2Result *=result; if(exp & 1) = = 1) {//determining the power of odd and even times, which is substituted for the remainder operationResult *=Base; }        returnresult; }

The whole number of points of the offer-value of the sword

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.