exponent

Strange behavior of R

﹥>﹥吖頭↗ 提交于 2019-12-31 03:09:06
问题 So, I have the following code in R: y a <- -0.1 test <- (1/((y+as.numeric(!y))*(a-1))) test test^a -0.9090909^a Giving me the output: > y [1] 0.00000000 0.06024096 0.00000000 0.01098901 0.00000000 0.00000000 [7] 0.01829268 0.00000000 0.06976744 0.00000000 0.04380665 0.01351351 [13] 0.00000000 0.00000000 0.00000000 0.00000000 0.00310559 0.00000000 [19] 0.00000000 0.00000000 0.09957447 0.00000000 0.03738318 0.00000000 > a <- -0.1 > test <- (1/((y+as.numeric(!y))*(a-1))) > test [1] -0.9090909

Converting unit abbreviations to numbers

╄→尐↘猪︶ㄣ 提交于 2019-12-29 07:55:12
问题 I have a dataset that abbreviates numerical values in a column. For example, 12M mean 12 million, 1.2k means 1,200. M and k are the only abbreviations. How can I write code that allows R to sort these values from lowest to highest? I've though about using gsub to convert M to 000,000 etc but that does not take into account the decimals (1.5M would then be 1.5000000). 回答1: So you want to translate SI unit abbreviations ('K','M',...) into exponents, and thus numerical powers-of-ten. Given that

C# Math.Pow() is broken

余生长醉 提交于 2019-12-29 07:52:29
问题 And no, this does not (to my understanding) involve integer division or floating-point rounding issues. My exact code is: static void Main(string[] args) { double power = (double)1.0 / (double)7.0; double expBase = -128.0; System.Console.WriteLine("sanity check: expected: -128 ^ 0.142857142857143 = -2. actual: " + expBase + " ^ " + power + " = " + Math.Pow(expBase, power)); System.Console.ReadLine(); } The output is: sanity check: expected: -128 ^ 0.142857142857143 = -2. actual: -128 ^ 0

C# Math.Pow() is broken

a 夏天 提交于 2019-12-29 07:52:08
问题 And no, this does not (to my understanding) involve integer division or floating-point rounding issues. My exact code is: static void Main(string[] args) { double power = (double)1.0 / (double)7.0; double expBase = -128.0; System.Console.WriteLine("sanity check: expected: -128 ^ 0.142857142857143 = -2. actual: " + expBase + " ^ " + power + " = " + Math.Pow(expBase, power)); System.Console.ReadLine(); } The output is: sanity check: expected: -128 ^ 0.142857142857143 = -2. actual: -128 ^ 0

How to calculate an arbitrary power/root?

家住魔仙堡 提交于 2019-12-29 07:01:54
问题 I have a application which needs to raise a number to a fractional power. The target platform is an FPGA and I can get estimates on an FPU size for it, but I need an algorithm for raising a number to a fractional power just for a feasibility study. I'm assuming floating point as a worst case, I expect in practice we will be able to use short cuts, but for now I want to show that worst case can be implemented on our part. Thought I'd ask here and see if there were any common methods that I

How to calculate an arbitrary power/root?

假如想象 提交于 2019-12-29 07:01:11
问题 I have a application which needs to raise a number to a fractional power. The target platform is an FPGA and I can get estimates on an FPU size for it, but I need an algorithm for raising a number to a fractional power just for a feasibility study. I'm assuming floating point as a worst case, I expect in practice we will be able to use short cuts, but for now I want to show that worst case can be implemented on our part. Thought I'd ask here and see if there were any common methods that I

How to calculate an arbitrary power/root?

巧了我就是萌 提交于 2019-12-29 07:01:08
问题 I have a application which needs to raise a number to a fractional power. The target platform is an FPGA and I can get estimates on an FPU size for it, but I need an algorithm for raising a number to a fractional power just for a feasibility study. I'm assuming floating point as a worst case, I expect in practice we will be able to use short cuts, but for now I want to show that worst case can be implemented on our part. Thought I'd ask here and see if there were any common methods that I

Python: raw_input and unsupported operand type(s)

流过昼夜 提交于 2019-12-29 02:06:14
问题 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

Generate all lists of size n, such that each element is between 0 and m (inclusive)

依然范特西╮ 提交于 2019-12-24 16:53:23
问题 Generate all lists of size n , such that each element is between 0 and m (inclusive). There are (m+1)^n such lists. 回答1: There are two easy ways of writing the general case. One is described in the existing answer from @didierc. The alternative is recursion. For example, think about a method that takes a String as an argument: if(input string is long enough) print or store it else iterate over digit range recursive call with the digit appended to the string 回答2: This is just like enumerating

Java DecimalFormat creates error when enforcing exponent sign

空扰寡人 提交于 2019-12-24 03:50:54
问题 In Java, I am trying to get DecimalFormat to enforce the sign on an exponent sign. When it is positive I need a plus sign to appear. From what I have read this seems like a no brainer, but for myself it always throws up an error. I appreciate that there may be other methods to achieve my goal, but I would like to understand why in this specific method the error is occurring. Double result = 123.456; String sresult; //This works NumberFormat formatter = new DecimalFormat("0.00000E00"); sresult