numeric

Converting from unsigned long long to float with round to nearest even

坚强是说给别人听的谎言 提交于 2019-12-05 14:18:26
I need to write a function that rounds from unsigned long long to float, and the rounding should be toward nearest even. I cannot just do a C++ type-cast, since AFAIK the standard does not specify the rounding. I was thinking of using boost::numeric, but i could not find any useful lead after reading the documentation. Can this be done using that library? Of course, if there is an alternative, i would be glad to use it. Any help would be much appreciated. EDIT: Adding an example to make things a bit clearer. Suppose i want to convert 0xffffff7fffffffff to its floating point representation. The

When to use DBL_EPSILON/epsilon

扶醉桌前 提交于 2019-12-05 13:37:52
The DBL_EPSILON/std::numeric_limits::epsilon will give me the smallest value that will make a difference when adding with one. I'm having trouble understanding how to apply this knowledge into something useful. The epsilon is much larger than the smallest value the computer can handle, so It would seem like a correct assumption that its safe to use smaller values than epsilon? Should the ratio between the values I'm working with be smaller than 1/epsilon ? AProgrammer The definition of DBL_EPSILON isn't that. It is the difference between the next representable number after 1 and 1 (your

python numpy.convolve to solve convolution integral with limits from 0 to t instead -t to t

偶尔善良 提交于 2019-12-05 08:54:05
I have a convolution integral of the type: To solve this integral numerically, I would like to use numpy.convolve() . Now, as you can see in the online help , the convolution is formally done from -infinity to +infinity meaning that the arrays are moved along each other completely for evaluation - which is not what I need. I obviously need to be sure to pick the correct part of the convolution - can you confirm that this is the right way to do it or alternatively tell me how to do it right and (maybe even more important) why? res = np.convolve(J_t, dF, mode="full")[:len(dF)] J_t is an

PostgreSQL adds trailing zeros to numeric

ε祈祈猫儿з 提交于 2019-12-05 05:32:39
Recently I migrated a DB to PostgreSQL that has some columns defined as numeric(9,3) and numeric(9,4) . In testing the app I have found that when data is saved to these columns there are trailing zeros being added to the value inserted. I am using Hibernate, and my logs show the correct values being built for the prepared statements. An example of the data I am inserting is 0.75 in the numeric(9,3) column and the value stored is 0.750 . Another example for the numeric(9,4) column: I insert the value 12 and the DB is holding 12.0000 . I found this related question: postgresql numeric type

Tracing Python warnings/errors to a line number in numpy and scipy

╄→гoц情女王★ 提交于 2019-12-05 00:43:40
I am getting the error: Warning: invalid value encountered in log From Python and I believe the error is thrown by numpy (using version 1.5.0). However, since I am calling the "log" function in several places, I'm not sure where the error is coming from. Is there a way to get numpy to print the line number that generated this error? I assume the warning is caused by taking the log of a number that is small enough to be rounded to 0 or smaller (negative). Is that right? What is the usual origin of these warnings? Putting np.seterr(invalid='raise') in your code (before the errant log call) will

Jquery check if value is numeric

二次信任 提交于 2019-12-04 22:29:48
I was wondering if anybody had a quick and dirty jquery method that will check if a value is numeric or not? I was thinking about using a regex type method to check the value, if not do not submit the form. I was using jquery validation, but I am running into issues just loading jquery validation. I just have one value that I want to make sure is numeric. Sure, use jQuery's isNumeric() function. $.isNumeric("-10"); // true $.isNumeric(16); // true $.isNumeric(0xFF); // true $.isNumeric("0xFF"); // true $.isNumeric("8e5"); // true (exponential notation string) $.isNumeric(3.1415); // true $

Why is numeric_limits<int>::max() > numeric_limits<int>::infinity()?

喜夏-厌秋 提交于 2019-12-04 22:22:15
I was reading Setting an int to Infinity in C++ . I understand that when one needs true infinity, one is supposed to use numeric_limits<float>::infinity() ; I guess the rationale behind it is that usually integral types have no values designated for representing special states like NaN , Inf , etc. like IEEE 754 floats do (again C++ doesn't mandate neither - int & float used are left to the implementation); but still it's misleading that max > infinity for a given type. I'm trying to understand the rationale behind this call in the standard. If having infinity doesn't make sense for a type,

Convert a date to an integer in YYYYMMDD format in SSRS

 ̄綄美尐妖づ 提交于 2019-12-04 18:34:15
What is the equivalent expression in SSRS of the following conversion of a date (@Date) in T-SQL? CONVERT(INT,CONVERT(CHAR,@Date,112)) I need the date parameter value to be converted to an integer in YYYYMMDD format. Assuming you have a date parameter called YourDate . You could use the following expression: =Cint(Format(Parameters!YourDate.Value, "yyyyMMdd")) Explanation: Step 1: Format the date to the yyyyMMdd format: Format(Parameters!YourDate.Value, "yyyyMMdd") Step 2: Cast the result as an int: Cint(<FormattedDate>) Dry coding here, but try... =Fields!MyDateColumn.Value.Year * 10000 +

More on generic Scala functions

亡梦爱人 提交于 2019-12-04 15:41:30
问题 Trying to implement, in Scala, the following Haskell function (from Learn You a Haskell...) so that it works with Int, Double, etc. doubleUs x y = x * 2 + y * 2 Note that this is similar to Scala: How to define "generic" function parameters? Here's my attempt and error. Can someone explain what's happening and offer a solution. Thanks. scala> def doubleUs[A](x:A,y:A)(implicit numeric: Numeric[A]): A = numeric.plus(numeric.times(x,2),numeric.times(y,2)) <console>:34: error: type mismatch;

Solving a system of transcendental equations with python

久未见 提交于 2019-12-04 12:03:15
Assuming I have the following four equations: cos(x)/x = a cos(y)/y = b a + b = 1 c sinc(x) = d sinc(y) for unknown variables x, y, a and b . Note that cos(x)/x=a has multiple solutions. Similar goes for variable y . I am only interested in x and y values, which are first positive roots (if that matters). You can safely assume a, b, c and d are known real constants, all positive. In Mathematica the code to solve this would look something like: FindRoot[{Cos[x]/x == 0.2 a + 0.1, Cos[y]/y == 0.2 b + 0.1, a + b == 1.0, 1.03*Sinc[x] == Sinc[y]*1.02}, {{x, .1}, {y, .1}, {a, .3}, {b, .1}}] which as