exponent

Convert numbers with exponential notation from string to double or decimal

送分小仙女□ 提交于 2019-11-27 06:39:18
问题 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); 回答1: 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

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

混江龙づ霸主 提交于 2019-11-27 05:07:27
问题 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

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

╄→尐↘猪︶ㄣ 提交于 2019-11-27 01:33:49
问题 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." 回答1: The IEEE 754 encodings have a convenient property that an order

Is there an exponent operator in C#?

心不动则不痛 提交于 2019-11-26 22:31:11
For example, does an operator exist to handle this? float Result, Number1, Number2; Number1 = 2; Number2 = 2; Result = Number1 (operator) Number2; In the past the ^ operator has served as an exponential operator in other languages, but in C# it is a bit-wise operator. Do I have to write a loop or include another namespace to handle exponential operations? If so, how do I handle exponential operations using non-integers? The C# language doesn't have a power operator . However, the .NET Framework offers the Math.Pow method: Returns a specified number raised to the specified power. So your

Raising to power in PHP

心不动则不痛 提交于 2019-11-26 17:21:19
问题 Well, i need to do some calculations in PHP script. And i have one expression that behaves wrong. echo 10^(-.01); Outputs 10 echo 1 / (10^(.01)); Outputs 0 echo bcpow('10', '-0.01') . '<br/>'; Outputs 1 echo bcdiv('1', bcpow('10', '0.01')); Outputs 1.000.... I'm using bcscale(100) for BCMath calculations. Excel and Wolfram Mathematica give answer ~0,977237. Any suggestions? 回答1: The caret is the bit-wise XOR operator in PHP. You need to use pow() for integers. 回答2: PHP 5.6 finally introduced

Python - number of digits in exponent

爷,独闯天下 提交于 2019-11-26 16:52:23
问题 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' 回答1: 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 +/

Python and Powers Math

一曲冷凌霜 提交于 2019-11-26 16:31:37
问题 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

Is there an exponent operator in C#?

♀尐吖头ヾ 提交于 2019-11-26 08:21:24
问题 For example, does an operator exist to handle this? float Result, Number1, Number2; Number1 = 2; Number2 = 2; Result = Number1 (operator) Number2; In the past the ^ operator has served as an exponential operator in other languages, but in C# it is a bit-wise operator. Do I have to write a loop or include another namespace to handle exponential operations? If so, how do I handle exponential operations using non-integers? 回答1: The C# language doesn't have a power operator. However, the .NET

Parse a Number from Exponential Notation

我的梦境 提交于 2019-11-26 03:30:46
问题 I need to parse the string \"1.2345E-02\" (a number expressed in exponential notation) to a decimal data type, but Decimal.Parse(\"1.2345E-02\") simply throws an error 回答1: It is a floating point number, you have to tell it that: decimal d = Decimal.Parse("1.2345E-02", System.Globalization.NumberStyles.Float); 回答2: It works if you specify NumberStyles.Float: decimal x = decimal.Parse("1.2345E-02", NumberStyles.Float); Console.WriteLine(x); // Prints 0.012345 I'm not entirely sure why this isn