exponent

Does Java have an exponential operator?

本小妞迷上赌 提交于 2019-11-28 20:46:34
问题 Is there an exponential operator in Java? For example, if a user is prompted to enter two numbers and they enter 3 and 2 , the correct answer would be 9 . import java.util.Scanner; public class Exponentiation { public static double powerOf (double p) { double pCubed; pCubed = p*p; return (pCubed); } public static void main (String [] args) { Scanner in = new Scanner (System.in); double num = 2.0; double cube; System.out.print ("Please put two numbers: "); num = in.nextInt(); cube = powerOf

Python: raw_input and unsupported operand type(s)

不打扰是莪最后的温柔 提交于 2019-11-28 14:44:05
I am a newbie to Python and have been recently attempting to create a BMI calculator, but I am having errors with the following code: def calculator(): weight = raw_input('Please enter your weight (kg):') if weight.isdigit and weight > 0: height = raw_input('Please enter your height (m):') if height.isdigit and height > 0: bmi = (weight) / (height ** 2) print "Your BMI is", bmi if bmi < 18.5: print 'You are underweight.' if bmi >= 18.5 and bmi < 25: print 'Your BMI is normal.' if bmi >= 25 and bmi < 30: print 'You are overweight.' if bmi >= 30: print 'You are obese.' else: height = raw_input(

Convert numbers with exponential notation from string to double or decimal

筅森魡賤 提交于 2019-11-28 11:58:51
Is there a fast way to convert numbers with exponential notation (examples: "0.5e10" or "-5e20") to decimal or double? Update: I found Parse a Number from Exponential Notation but the examples won't work for me unless I specified a culture. Solution: double test = double.Parse("1.50E-15", CultureInfo.InvariantCulture); If your culture uses . as the decimal separator, just double.Parse("1.50E-15") should work. If your culture uses something else (e.g. , ) or you want to make sure your application works the same on every computer, you should use InvariantCulture : double.Parse("1.50E-15",

Why do we bias the exponent of a floating-point number?

北城余情 提交于 2019-11-28 06:52:39
I'm trying to wrap my head around this floating point representation of binary numbers, but I couldn't find, no matter where I looked, a good answer to the question. Why is the exponent biased? What's wrong with the good old reliable two's complement method? I tried to look at the Wikipedia's article regarding the topic, but all it says is: "the usual representation for signed values, would make comparison harder." The IEEE 754 encodings have a convenient property that an order comparison can be performed between two positive non-NaN numbers by simply comparing the corresponding bit strings

Rounding to a power of 10

这一生的挚爱 提交于 2019-11-28 03:11:52
问题 I have a variable, tauMax , that I want to round up to the nearest power of ten(1, 10, 100, 1000...). I am using the below expression to find the closest integer to the max value in the tau array. I am finding the max value because I am trying to calculate the power of ten that should be the x axis cutoff. In this cause, tauMax is equal to 756, so I want to have an expression that outputs either 1000, or 3(for 10^3). tauMax = round(max(tau)); I'd really appreciate any help! 回答1: Since you're

Optimizations for pow() with const non-integer exponent?

空扰寡人 提交于 2019-11-28 03:08:12
I have hot spots in my code where I'm doing pow() taking up around 10-20% of my execution time. My input to pow(x,y) is very specific, so I'm wondering if there's a way to roll two pow() approximations (one for each exponent) with higher performance: I have two constant exponents: 2.4 and 1/2.4. When the exponent is 2.4, x will be in the range (0.090473935, 1.0]. When the exponent is 1/2.4, x will be in the range (0.0031308, 1.0]. I'm using SSE/AVX float vectors. If platform specifics can be taken advantage of, right on! A maximum error rate around 0.01% is ideal, though I'm interested in full

Python - number of digits in exponent

纵饮孤独 提交于 2019-11-27 14:37:27
Is it possible to set the number of digits to be used for printing the exponent of a floating-point number? I want to set it to 3. Currently, f = 0.0000870927939438012 >>> "%.14e"%f '8.70927939438012e-05' >>> "%0.14e"%f '8.709279e-005' What I want to print is: '8.70927939438012e-005' There is a no way to control that, best way is to write a function for this e.g. def eformat(f, prec, exp_digits): s = "%.*e"%(prec, f) mantissa, exp = s.split('e') # add 1 to digits as 1 is taken by sign +/- return "%se%+0*d"%(mantissa, exp_digits+1, int(exp)) print eformat(0.0000870927939438012, 14, 3) print

JSON standard - floating point numbers

女生的网名这么多〃 提交于 2019-11-27 14:18:42
问题 I am wondering whether the following floating point notation is a valid JSON notation: "result":{"base_fee":1e-005} or should the exponent notation be replaced with a decimal notation? 回答1: It is valid according to the format available at json.org as numbers can optionally have a base 10 exponent denoted by an E, uppercase or lowercase, an optional plus or minus, and one or more digits. 回答2: It's perfectly valid, according to RFC 4627 RFC 7159*: The representation of numbers is similar to

Python and Powers Math

时光毁灭记忆、已成空白 提交于 2019-11-27 13:53:16
I've been learning Python but I'm a little confused. Online instructors tell me to use the operator ** as opposed to ^ when I'm trying to raise to a certain number. Example: print 8^3 Gives an output of 11. But what I'm look for (I'm told) is more akin to: print 8**3 which gives the correct answer of 512. But why? Can someone explain this to me? Why is it that 8^3 does not equal 512 as it is the correct answer? In what instance would 11 (the result of 8^3)? I did try to search SO but I'm only seeing information concerning getting a modulus when dividing. Operator ^ is a bitwise operator ,

Why does python add an 'L' on the end of the result of large exponents? [duplicate]

不羁岁月 提交于 2019-11-27 07:59:42
This question already has an answer here: Why do integers in database row tuple have an 'L' suffix? 3 answers If you've noticed, python adds an L on to the end of large exponent results like this: >>> 25 ** 25 88817841970012523233890533447265625L After doing some tests, I found that any number below 10 doesn't include the L . For example: >>> 9 ** 9 387420489 This was strange, so, why does this happen, is there any method to prevent it? All help is appreciated! Python supports arbitrary precision integers, meaning you're able to represent larger numbers than a normal 32 or 64 bit integer type.