简体   繁体   中英

How to check if denominator of double number is odd?

I get 2 double numbers - basic and pow , and I have to calculate basic^power . My problem is that there is cases should throw error - like if the pow is a fraction like odd/even and the basic is a negative - for example basic=(-2) and pow=0.75=(3\\4) So it should be (-2)^3=-8 and then root 4 of -8 means error . so how can I detect such cases ?

From the man page of pow() :

pow(x, y) returns a NaN and raises the "invalid" floating-point exception for finite x < 0 and finite non-integer y.

So check for this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM