double

Ordering operation to maximize double precision

巧了我就是萌 提交于 2019-12-10 09:56:25
问题 I'm working on some tool that gets to compute numbers that can get close to 1e-25 in the worst cases, and compare them together, in Java. I'm obviously using double precision. I have read in another answer that I shouldn't expect more than 1e-15 to 1e-17 precision, and this other question deals with getting better precision when ordering operations in a "better" order. Which double precision operations are more keen to loose precision along the way? Should I try to work with number as big as

convert double to float in Python

前提是你 提交于 2019-12-10 04:34:05
问题 In a Python program, I have these two values: v1 = 0.00582811585976 v2 = 0.00582811608911 My hypothesis is that v1 is a 64-bits floating point value, and v2 is v1 converted to a 32-bits floating point value. How can I verify this? Details: The first value comes from a hardware board that calculates with 64-bits precision. The board sends the value to a PC, but it should also convert the value to 32-bits precision and send that to another board, which in turn sends it to a PC. I just want to

Are Java integer-type primitive casts “capped” at the MAX_INT of the casting type?

為{幸葍}努か 提交于 2019-12-10 03:48:44
问题 I was trying to track down some very weird Java behavior. I have a formula that involves a double, but is "guaranteed" to give an integer answer -- specifically, an unsigned 32-bit integer (which, alas, Java doesn't do well). Unfortunately, my answers were sometimes incorrect. Eventually I found the issue, but the behavior is still very odd to to me: a double cast directly to an int seems to be capped at the MAX_INT for a signed integer, whereas a double cast to a long that is then cast to an

Macro or function to construct a float (double) from a given sign, mantissa and exponent?

一世执手 提交于 2019-12-10 02:44:47
问题 Is there any macro or function to construct a float (double) from a given sign, mantissa and exponent (all binary or decimal) that either returns a valid float (double) number or returns NaN if the number specified by input is not representable as float (double)? 回答1: The function you're looking for is ldexp . 来源: https://stackoverflow.com/questions/9639375/macro-or-function-to-construct-a-float-double-from-a-given-sign-mantissa-and

Convert vector<double> to vector<string> ( elegant way )

血红的双手。 提交于 2019-12-10 01:50:20
问题 I would like to know if there is an elegant way or a built-in function to convert vector<double> to vector<string> . What I've done is simple #include <iostream> #include <string> #include <vector> #include <sstream> std::vector<std::string> doubeVecToStr(const std::vector<double>& vec) { std::vector<std::string> tempStr; for (unsigned int i(0); i < vec.size(); ++i){ std::ostringstream doubleStr; doubleStr << vec[i]; tempStr.push_back(doubleStr.str()); } return tempStr; } int main( int argc,

How to divide tiny double precision numbers correctly without precision errors?

被刻印的时光 ゝ 提交于 2019-12-10 01:42:07
问题 I'm trying to diagnose and fix a bug which boils down to X/Y yielding an unstable result when X and Y are small: In this case, both cx and patharea increase smoothly. Their ratio is a smooth asymptote at high numbers, but erratic for "small" numbers. The obvious first thought is that we're reaching the limit of floating point accuracy, but the actual numbers themselves are nowhere near it. ActionScript "Number" types are IEE 754 double-precision floats, so should have 15 decimal digits of

Why does Assert.AreEqual(1.0, double.NaN, 1.0) pass?

被刻印的时光 ゝ 提交于 2019-12-10 01:10:02
问题 Short question, why does Assert.AreEqual(1.0, double.NaN, 1.0) pass? Whereas Assert.AreEqual(1.0, double.NaN) fails. Is it a bug in MSTest (Microsoft.VisualStudio.QualityTools.UnitTestFramework) or am I missing something here? Best regards, Egil. Update: Should probably add, that the reason behind my question is, that I have a bunch of unit tests that unfortunately passed due to the result of some linear algebraic matrix operation being NaN or (+/-)Infinity. The unit tests are fine, but since

convert double value to binary value

穿精又带淫゛_ 提交于 2019-12-09 18:25:52
问题 How can i convert double value to binary value. i have some value like this below 125252525235558554452221545332224587265 i want to convert this to binary format..so i am keeping it in double and then trying to convert to binary (1 & 0's).. i am using C#.net 回答1: Well, you haven't specified a platform or what sort of binary value you're interested in, but in .NET there's BitConverter.DoubleToInt64Bits which lets you get at the IEEE 754 bits making up the value very easily. In Java there's

Java - maximum loss of precision in one double addition/subtraction

拟墨画扇 提交于 2019-12-09 17:28:06
问题 Is it possible to establish, even roughly, what the maximum precision loss would be when dealing with two double values in java (adding/subtracting)? Probably the worst case scenario is when two numbers cannot be represented exactly, and then an operation is performed on them, which results in a value that also cannot be represented exactly. 回答1: Have a look at Math.ulp(double). The ulp of a double is the delta to the next highest value. For instance, if you add to numbers and one is smaller

Checking if a variable is of data type double

家住魔仙堡 提交于 2019-12-09 10:57:09
问题 I need to check if a variable I have is of the data type double . This is what I tried: try { double price = Convert.ToDouble(txtPrice.Text); } catch (FormatException) { MessageBox.Show("Product price is not a valid price", "Product price error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } I thought this would work, but obviously, I failed to realize if txtPrice.Text had anything other than a number in it, the Convert class will just parse it out. How can I realiably check if