multiplication

Double variable keeping wrong value

最后都变了- 提交于 2019-12-02 07:34:16
Simimilar problem to Math.Atan2 or class instance problem in C# and add two double given wrong result It is something that simple lines: public static String DegreeToRadianStr(Double degree) { Double piBy180 = (Math.PI / 180); Double Val = (piBy180 * degree); // Here it is giving wrong value } piBy180 * degree = -3.1415926535897931 but Val = -3.1415927410125732 alt text http://www.imagechicken.com/uploads/1262936639009840000.jpg I really have no clue what to do .. Please ask some questions regarding this, so that I can point out where it is going wrong. It is amazing that piBy180 is keeping

How do I move the result of a mul of two floats in x86 assembly?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 07:16:15
I am currently trying to multiply two floats, one that comes from a float vector (address stored in ebx) and against the value I stored in ecx. I have confirmed that the input values are correct, however, if I multiply 32 and 1, for example, the value in EAX changes to 00000000 and the one in EDX to 105F0000. From my understanding of MUL, this happens because it is storing the high order bits of the result in EDX and the low order ones in EDX. Question is, how do I move the result into an output variable (returnValue) ? Here is the code snippet in question: AddColumnsIteration: cmp esi, 4 //

How do I multiply a dataframe column by a float constant?

天涯浪子 提交于 2019-12-02 05:05:09
I'm trying to multiply a column by a float. I have the code for it here: if str(cMachineName)==str("K42"): df_temp.loc[:, "P"] *= float((105.0* 59.0*math.pi*0.95/1000)/3540) But it gives me this error: TypeError: can't multiply sequence by non-int of type 'float'. How do I solve it? I think problem is some non numeric values like 45 as string: Solution is converting to float , int by astype : df_temp = pd.DataFrame({'P':[1,2.5,'45']}) print (df_temp['P'].dtype) object df_temp["P"] = df_temp["P"].astype(float) df_temp["P"] *= float((105.0* 59.0*math.pi*0.95/1000)/3540) print (df_temp) P 0 0

Multiply numbers without using instructions MUL, IMUL, SHL, SHR, LOOP

限于喜欢 提交于 2019-12-02 04:55:33
问题 Is it possible to calculate result of multiplication without using instructions MUL, IMUL, SHL, SHR, LOOP, JMP in x86 assembly language? 回答1: The following code will multiply the contents of the registers ecx and edx and store the result in register eax . The content of the registers ebx and edx is destroyed: mov ebx, 1 mov eax, 0 repeat: test ecx, ebx jz dontadd add eax, edx dontadd: add edx, edx add ebx, ebx jnz repeat without ... LOOP If "LOOP" does not only cover the "LOOP" instruction

Floating point multiplication in java [duplicate]

社会主义新天地 提交于 2019-12-02 03:47:22
Possible Duplicate: How to round a number to n decimal places in Java When multiplying two numbers in java happens this: double a = 9.495 * 100; Expected result: a = 949.5; But the obtained result is: a = 949.4999999999999 When I try to round number 9.495 in two decimal places the result is 9.49 instead of 9.50 Any ideas how to solve this problem? If you want accurate floating point computations, do not use the float or double types, but rather make use of the BigDecimal class. You cannot. Floating point and double precision numbers in a computer cannot represent all possible values. This is a

Multiply numbers without using instructions MUL, IMUL, SHL, SHR, LOOP

老子叫甜甜 提交于 2019-12-02 01:45:23
Is it possible to calculate result of multiplication without using instructions MUL, IMUL, SHL, SHR, LOOP, JMP in x86 assembly language? The following code will multiply the contents of the registers ecx and edx and store the result in register eax . The content of the registers ebx and edx is destroyed: mov ebx, 1 mov eax, 0 repeat: test ecx, ebx jz dontadd add eax, edx dontadd: add edx, edx add ebx, ebx jnz repeat without ... LOOP If "LOOP" does not only cover the "LOOP" instruction but any conditional jump instructions: Doing a multiplication without conditional jump instructions is a bit

Simulating Floating Point Multiplication in C using Bitwise Operators [closed]

放肆的年华 提交于 2019-12-02 00:50:00
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 10 months ago . I have to write a program that will simulate floating point multiplication. For this program, we assume that a single precision floating point number is stored in unsigned long a . I have to multiply the number stored in a by 2 using only the following operators: << >> | & ~ ^ I

Efficient product of 1D array and 3D array along one dimension - NumPy

半城伤御伤魂 提交于 2019-12-01 22:05:08
I have two numpy arrays: A 1D array called t of shape (70L,) with element called let s say ti A 3D array called I with shape (70L, 1024L, 1024L), with each elements called Ii. Ii are thus of dimension (1024L, 1024L) I would like to make a product of the two array along the first dimension, i.e.: tI = t1*I1,t2*I2,...,tN*IN such as to obtain again a new array of dimension (70L, 1024L, 1024L) and then take the sum along the first dimension in order to obtain an array of dimension (1024L, 1024L): tsum = t1*I1 + t2*I2 + ... +tN*IN For the moment I am satisfied with doing the following: tI = np

Matrix multiplication in R: requires numeric/complex matrix/vector arguments

房东的猫 提交于 2019-12-01 21:59:54
I'm using the dataset BreastCancer in the mlbench package, and I am trying to do the following matrix multiplication as a part of logistic regression. I got the features in the first 10 columns, and create a vector of parameters called theta: X <- BreastCancer[, 1:10] theta <- data.frame(rep(1, 10)) Then I did the following matrix multiplication: constant <- as.matrix(X) %*% as.vector(theta[, 1]) However, I got the following error: Error in as.matrix(X) %*% as.vector(theta[, 1]) : requires numeric/complex matrix/vector arguments Do I need to cast the matrix to double using as.numeric(X) first?

Is there a method in numpy to multiply every element in an array?

十年热恋 提交于 2019-12-01 21:59:21
问题 I want to multiply all elements in a numpy array. If there's an array like [1,2,3,4,5] , I want to get value of 1*2*3*4*5 . I tried this by making my own method, but size of array is very large, it takes very longs time to calculate because I'm using numpy it would be helpful if numpy supports this operation. I tried to find out through numpy documents, but I failed. Is there a method which does this operation? If there is, is there a way to get values along a rank in an matrix? 回答1: I