precision

Displayed precision of Java floating-point

萝らか妹 提交于 2019-12-14 03:28:50
问题 If we run the following code: float f = 1.2345678990922222f; double d = 1.22222222222222222222d; System.out.println("f = " + f + "\t" + "d = " + d); it prints: f = 1.2345679 d = 1.2222222222222223 The long tail in the literal 1.2345678990922222 is ignored but the long tail in 1.22222222222222222222 is not (the last decimal digit in the variable d becomes 3 instead of 2). Why? 回答1: The number of digits you see when a float or a double is printed is a consequence of Java’s rules for default

Taking Modulo of Double NUmber

孤人 提交于 2019-12-14 02:08:17
问题 I have given two number a and b .I have to Calculate (a^b)%1000000007 .How Can i calculate for floating point numbers. Ex: a= 7.654 and b=10000 Here is my Code will % work : public static double super_pow(double A , long B){ double o=1; while(B>0){ if((B&1)!=0) o*=A; A*=A; B/=2; o%=mod; A%=mod; } return (o)%mod; } 回答1: In java you can use the modulo operation for floats/doubles (How do I use modulus for float/double?) If you have to calculate (a^b)%1000000007 you can use double for a and b

Java precision during division and multiplication alterneting process [duplicate]

左心房为你撑大大i 提交于 2019-12-13 22:03:55
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How to resolve a Java Rounding Double issue Please Help, I programm some calculator in Java. I use double type. Double has 15 digits after the decimal point. I have problem with the following: 1/3 * 3 = 0.9999999999999999 I need 1/3 * 3 = 1 How can I solve this problem? I keep result in Double. The same problem I have with other mathematical operations, for example sqrt(6) = 2.449489742783, and next I square the

Now() Accuracy in VBScript

走远了吗. 提交于 2019-12-13 17:57:44
问题 Now() in VBScript appears to return time in 10,000,000th of a second precision when called as CDbl(Now()). In attempting to use this to write a more accurate implementation of now which returns CIM_DATETIME format I found that in VBScript, despite being particularly precise, is not very accurate with the time only updating once per second. This can be demonstrated by watching the output from what follows: i = 0 While i < 50 gnow = Cdbl(now) result = (gnow - Int(gnow)) WScript.Echo CDate(gnow)

How to perform precise calculations in Python, regardless of input types?

China☆狼群 提交于 2019-12-13 17:14:50
问题 I need to make computations in the highest possible precision, regardless if the arguments passed are integers, floats or whatever numbers . One way I can think of this is: import numpy as np def foo(x, y, z) a = (np.float64)0 a = x + y * z I can see a couple of problems with this: 1) I think I need to convert the inputs, not the result for this to work 2)looks ugly (the first operation is a superfluous C-style declaration). How can I pythonically perform all calculations in the highest

What's the tolerance of the which.max function in R?

流过昼夜 提交于 2019-12-13 17:05:41
问题 Based on a problem I discussed here: https://stackoverflow.com/a/57364028/2725773 I'm wondering what's the tolerance/precision of the which.max function in R. Specifically, the alternative max.col function has a tolerance of 1e-5, which means that 0.12345 is the same for it as 0.12346. The help page for max.col suggests an alternative, namely using unname(apply(m, 1, which.max)) , which brings me to the questions what's the tolerance of which.max ? 回答1: Fascinating question. I do not know the

Fixed Point Cholesky Algorithm Advantages

空扰寡人 提交于 2019-12-13 16:16:54
问题 I am developing some code that can get its data from the HW in floating or fixed point. Currently we get that as floating point. The low layer APIs are all in fixed point. So we must pass data back as fixed point. The algorithm we are using is Cholesky. I am wondering why we must use floating point for Cholesky and not just get the data as fixed point. Are there any advantages in doing that? I would have thought that using floating point would have caused more rounding error. 回答1: The main

round() breaks when PHP precision is set to 18+

守給你的承諾、 提交于 2019-12-13 14:28:41
问题 When I set PHP's precision setting to values 18 or higher (whether in php.ini or at runtime), the round() function yields unexpected results. Is this a bug; or what am I missing? Results for e.g. rounding the float 12.4886724321 to 4 decimal precision are as follows: 14: 12.4887 ... 17: 12.4887 18: 12.4886999999999997 19: 12.48869999999999969 20: 12.48869999999999969 21: 12.4886999999999996902 22: 12.4886999999999996902 23: 12.488699999999999690203 24: 12.4886999999999996902034 Test case as

How to truncate floating points imprecision in python

扶醉桌前 提交于 2019-12-13 13:22:06
问题 I am writing a program for which it is important to compare and rank values in a date series. However, I am running into problems with the imprecision of floats I am pulling these data from my SQL server that are both supposed to be 1.6. However, they turn out to be slightly different (see below). Therefore, when I use dataframe.rank(), it doesn't treat these two dates as the same rank, but rather ranks 01/02/2004 above 02/01/2005. Anyone have any idea how to deal with this so that these two

printf a float value with precision (number of decimal digits) passed in a variable [duplicate]

耗尽温柔 提交于 2019-12-13 12:09:59
问题 This question already has answers here : Printf variable number of decimals in float (2 answers) Closed 3 years ago . I can print a float value with precision of 3 decimal digits with double f = 1.23456; printf( "%.3f", f ); Now I have the number of requested decimal digits that is not fixed but stored into a variable int precision; precision = atoi( argv[ 1 ] ); // ...just for example double f = 1.23456; How do I print the value of f with the number of decimal digits specified in precision ?