numerical

Are the character digits ['0'..'9'] required to have contiguous numeric values?

假如想象 提交于 2019-11-27 15:27:46
Must a C++ implementation set the chars '0'-'9' to have contiguous numeric values, i.e. so that: '0' -> 0+n '1' -> 1+n m -> m+n '9' -> 9+n I cannot find it mentioned in the documentation of isdigit ([classification] (22.3.3.1 Character classification)) * , nor can I find it in the locale documentation (but maybe I did not look hard enough). In 2.3 Character sets, we find that The basic source character set consists of 96 characters: the space character, the control characters representing horizontal tab, vertical tab, form feed, and new-line, plus the following 91 graphical characters But it

Plotting a line over several graphs

╄→гoц情女王★ 提交于 2019-11-27 14:00:22
I don't know how this thing is called, or even how to describe it, so the title may be a little bit misleading. The first attached graph was created with pyplot. I would like to draw a straight line that goes through all graphs instead of the three red dot I currently use. Is it possible in pyplot? Second image is what I am looking for. You can pull this off by turning clipping off for the relevant lines. There's probably a cleaner way to do this -- you might be able to draw lines on the main frame directly -- but the following worked for me: from matplotlib import pyplot as plt from numpy

Efficient way to compute geometric mean of many numbers

时光怂恿深爱的人放手 提交于 2019-11-27 12:49:47
问题 I need to compute the geometric mean of a large set of numbers, whose values are not a priori limited. The naive way would be double geometric_mean(std::vector<double> const&data) // failure { auto product = 1.0; for(auto x:data) product *= x; return std::pow(product,1.0/data.size()); } However, this may well fail because of underflow or overflow in the accumulated product (note: long double doesn't really avoid this problem). So, the next option is to sum-up the logarithms: double geometric

Extract contours from ContourPlot in Mathematica

有些话、适合烂在心里 提交于 2019-11-27 11:20:22
问题 I have a function f(x,y) of two variables, of which I need to know the location of the curves at which it crosses zero. ContourPlot does that very efficiently (that is: it uses clever multi-grid methods, not just a brute force fine-grained scan) but just gives me a plot. I would like to have a set of values {x,y} (with some specified resolution) or perhaps some interpolating function which allows me to get access to the location of these contours. Have thought of extracting this from the

Fastest 128 bit integer library [closed]

╄→尐↘猪︶ㄣ 提交于 2019-11-27 01:53:42
问题 I am working on a CPU-heavy numerical computation app. Without going into many details, it's a computational math research project that involves computing a certain function f(x) for large integer x. Right now everything is implemented in C++ in x64 mode, using native 64-bit ints. That limits me to x<2^64~1.8*10^19. I want to go further, to do that, I need a library that does 128-bit arithmetic. And it has to be very fast. In particular, integer divisions should be fast. Otherwise I'll be

Does JavaScript have double floating point number precision?

£可爱£侵袭症+ 提交于 2019-11-27 01:48:53
I know it's an odd question, but does JavaScript have the capacity to work with double's as opposed to single floats? (64 bit floats vs. 32 bits.) Moin Zaman All numbers in JavaScript are 64-bit floating point numbers. Ref: http://www.hunlock.com/blogs/The_Complete_Javascript_Number_Reference http://www.crockford.com/javascript/survey.html According to the ECMA-262 specification (ECMAScript is the specification for Javascript), section 8.5: The Number type has exactly 18437736874454810627 (that is, 2 64 −2 53 +3) values, representing the double-precision 64-bit format IEEE 754 values as

SQL ORDER chars numerically

流过昼夜 提交于 2019-11-27 01:28:09
问题 I have a column of numbers stored as chars. When I do a ORDER BY for this column I get the following: 100 131 200 21 30 31000 etc. How can I order these chars numerically? Do I need to convert something or is there already an SQL command or function for this? Thank You. 回答1: Try this: ORDER BY CAST(thecolumn AS int) 回答2: This Worked for me: ORDER BY ABS(column_name) 回答3: This is an issue with ordering numeric strings in a "natural sort" (if you lookup "natural sorting" on Google you'll find

Matlab gives wrong answer

匆匆过客 提交于 2019-11-26 22:03:15
问题 If the following code is executed MATLAB makes a mistake. Can someone verify this? floor([0.1:0.1:2]/0.01) So what is the 129 doing here?? ans = 10 20 30 40 50 60 70 80 90 100 110 120 129 140 150 160 170 180 190 200 回答1: It is a floating point rounding error because of the colon-generated vector. Like Rasman said, if you do: floor((0.1:0.1:2 + eps) / 0.01) There will be no rounding errors. However, based on how the colon operator works, I suggest that you do the same calculation like this:

Is one's complement a real-world issue, or just a historical one?

坚强是说给别人听的谎言 提交于 2019-11-26 20:30:49
Another question asked about determining odd/evenness in C, and the idiomatic (x & 1) approach was correctly flagged as broken for one's complement-based systems, which the C standard allows for. Do systems really exist in the 'real world' outside of computer museums? I've been coding since the 1970's and I'm pretty sure I've never met such a beast. Is anyone actually developing or testing code for such a system? And, if not, should we worry about such things or should we put them into Room 101 along with paper tape and punch cards...? Adam Haile This all comes down to knowing your roots. Yes,

Are the character digits ['0'..'9'] required to have contiguous numeric values?

廉价感情. 提交于 2019-11-26 18:31:42
问题 Must a C++ implementation set the chars '0'-'9' to have contiguous numeric values, i.e. so that: '0' -> 0+n '1' -> 1+n m -> m+n '9' -> 9+n I cannot find it mentioned in the documentation of isdigit ([classification] (22.3.3.1 Character classification)) * , nor can I find it in the locale documentation (but maybe I did not look hard enough). In 2.3 Character sets, we find that The basic source character set consists of 96 characters: the space character, the control characters representing