numeric

Associativity math: (a + b) + c != a + (b + c)

荒凉一梦 提交于 2019-11-28 22:17:37
Recently I was going through an old blog post by Eric Lippert in which, while writing about associativity he mentions that in C#, (a + b) + c is not equivalent to a + (b + c) for certain values of a, b, c. I am not able to figure out for what types and range of arithmetic values might that hold true and why. On the range of the double type: double dbl1 = (double.MinValue + double.MaxValue) + double.MaxValue; double dbl2 = double.MinValue + (double.MaxValue + double.MaxValue); The first one is double.MaxValue , the second one is double.Infinity On the precision of the double type: double dbl1 =

Right way to convert data.frame to a numeric matrix, when df also contains strings?

怎甘沉沦 提交于 2019-11-28 14:36:00
问题 I have a data frame taken from a .csv-file which contains numeric and character values. I want to convert this data frame into a matrix. All containing information is numbers (the non-number-rows I deleted), so it should be possible to convert the data frame into a numeric matrix. However, I do get a character matrix. I found the only way to solve this is to use as.numeric for each and every row, but this is quite time-consuming. I am quite sure there is a way to do this with some kind of if

php preg_match_all numbers in parentheses

落花浮王杯 提交于 2019-11-28 14:29:13
I am trying to load a remote website and get all numbers that are inside of parentheses. But what ends up happening is it only matches the last value. Is my regex wrong? Am I using the correct flags? I have added the example of what it should match on in the second $html variable. //$html = file_get_contents("http://example.com/test.html"); $html = "(1234) (12) (1) \r\n (1346326)"; preg_match_all("^[(\d)]+$^", $html, $matches, PREG_PATTERN_ORDER); print_r($matches); echo "<br>"; foreach ($matches as $val) { echo "matched: " . $val[0] . "\n"; } Thanks. How about: preg_match_all("/\((\d+)\)/",

How do I construct a std::string from a DWORD?

百般思念 提交于 2019-11-28 13:17:37
I have following code: Tools::Logger.Log(string(GetLastError()), Error); GetLastError() returns a DWORD a numeric value, but the constructor of std::string doesn't accept a DWORD . What can I do? You want to read up on ostringstream: #include <sstream> #include <string> int main() { std::ostringstream stream; int i = 5; stream << i; std::string str = stream.str(); } Johannes Schaub - litb You want to convert the number to a string : std::ostringstream os; os << GetLastError(); Log(os.str(), Error); Or boost::lexical_cast : Log(boost::lexical_cast<std::string>(GetLastError()), Error); Since C+

jquery numeric textbox with min and max ranges

僤鯓⒐⒋嵵緔 提交于 2019-11-28 11:34:01
i see this question but none of the solutions support min and max values range How to allow only numeric (0-9) in HTML inputbox using jQuery? I see that http://jstepper.emkay.dk/ attempts to do this but seems very buggy as it allows you to enter multiple decimal places and other characters such as ";". is there i way i can use one of these solutions and also say, only support min of 0 and max of 100 in the textbox entry? I am the author of jStepper and I just updated the plugin to be able to do what you like. So give it a try again and see if it works now :) HTML5 way of adding such fields.

Only allowing up to three digit numeric characters in a text box

随声附和 提交于 2019-11-28 11:13:19
问题 Is there a way to only allow a user to input a maximum number of characters into a text box? I want the user to input a mark/grade and only be able to input 0 - 100. Below I have code that monitors the keystroke and only allows for numbers to be input, but I want to find a way to only allow the user to input a number with a minimum value of 0 and a maximum of 100. private void TxtMark4_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar < '0' || e.KeyChar > '9' || e.KeyChar == ' ') {

Java: Format number in millions

北城余情 提交于 2019-11-28 11:05:55
Is there a way to use DecimalFormat (or some other standard formatter) to format numbers like this: 1,000,000 => 1.00M 1,234,567 => 1.23M 1,234,567,890 => 1234.57M Basically dividing some number by 1 million, keeping 2 decimal places, and slapping an 'M' on the end. I've thought about creating a new subclass of NumberFormat but it looks trickier than I imagined. I'm writing an API that has a format method that looks like this: public String format(double value, Unit unit); // Unit is an enum Internally, I'm mapping Unit objects to NumberFormatters. The implementation is something like this:

Finding rows that don't contain numeric data in Oracle

試著忘記壹切 提交于 2019-11-28 09:04:57
I am trying to locate some problematic records in a very large Oracle table. The column should contain all numeric data even though it is a varchar2 column. I need to find the records which don't contain numeric data (The to_number(col_name) function throws an error when I try to call it on this column). I was thinking you could use a regexp_like condition and use the regular expression to find any non-numerics. I hope this might help?! SELECT * FROM table_with_column_to_search WHERE REGEXP_LIKE(varchar_col_with_non_numerics, '[^0-9]+'); Michael Durrant To get an indicator: DECODE( TRANSLATE

How to set up implicit conversion to allow arithmetic between numeric types?

风格不统一 提交于 2019-11-28 08:40:28
I'd like to implement a class C to store values of various numeric types, as well as boolean. Furthermore, I'd like to be able to operate on instances of this class, between types, converting where necessary Int --> Double and Boolean -> Int , i.e., to be able to add Boolean + Boolean , Int + Boolean , Boolean + Int , Int + Double , Double + Double etc., returning the smallest possible type ( Int or Double ) whenever possible. So far I came up with this: abstract class SemiGroup[A] { def add(x:A, y:A):A } class C[A] (val n:A) (implicit val s:SemiGroup[A]) { def +[T <% A](that:C[T]) = s.add

How to get bc to handle numbers in scientific (aka exponential) notation?

a 夏天 提交于 2019-11-28 07:12:51
bc doesn't like numbers expressed in scientific notation (aka exponential notation). $ echo "3.1e1*2" | bc -l (standard_in) 1: parse error but I need to use it to handle a few records that are expressed in this notation. Is there a way to get bc to understand exponential notation? If not, what can I do to translate them into a format that bc will understand? Ferdinando Randisi Unfortunately, bc doesn't support scientific notation. However, it can be translated into a format that bc can handle, using extended regex as per POSIX in sed: sed -E 's/([+-]?[0-9.]+)[eE]\+?(-?)([0-9]+)/(\1*10^\2\3)/g'