Questions tagged [numeric]

This tag is for questions concerning problems using numbers which either cannot be exactly solved, or where the exact solution may be much more difficult to acquire than by using numerical methods.

This tag is for questions concerning problems using numbers which either cannot be exactly solved, or where the exact solution may be much more difficult to acquire than by using numerical methods.

It includes questions about algorithms, precision and accuracy of underlying numbers, advantages and disadvantages of several methods, error propagation, problems with the underlying numbers and data structures.

2593 questions
39
votes
4 answers

How to convert entire dataframe to numeric while preserving decimals?

I have a mixed class dataframe (numeric and factor) where I am trying to convert the entire data frame to numeric. The following illustrates the type of data I am working with as well as the problem I am encountering: > a =…
Borealis
  • 8,044
  • 17
  • 64
  • 112
38
votes
1 answer

Is there any trait that specifies numeric functionality?

I'd like to use a trait to bound a generic type, like this hypothetical HasSQRT: fn some_generic_function(input: &T) where T: HasSQRT, { // ... input.sqrt() // ... }
Hossein Noroozpour
  • 1,091
  • 1
  • 13
  • 26
38
votes
1 answer

Clarification of L in R

My trail on L in R is: c<-1:10 c # [1] 1 2 3 4 5 6 7 8 9 10 c[-1] # [1] 2 3 4 5 6 7 8 9 10 c[-2] # [1] 1 3 4 5 6 7 8 9 10 c[-1L] # [1] 2 3 4 5 6 7 8 9 10 c[-2L] # [1] 1 3 4 5 6 7 8 9 10 I tried using ?L…
useR
  • 3,062
  • 10
  • 51
  • 66
37
votes
10 answers

Open source alternative to MATLAB's fmincon function?

Is there an open-source alternative to MATLAB's fmincon function for constrained linear optimization? I'm rewriting a MATLAB program to use Python / NumPy / SciPy and this is the only function I haven't found an equivalent to. A NumPy-based solution…
dF.
  • 74,139
  • 30
  • 130
  • 136
36
votes
9 answers

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

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…
Roddy
  • 66,617
  • 42
  • 165
  • 277
34
votes
10 answers

converting a number base 10 to base 62 (a-zA-Z0-9)

I have a number in base 10. Is there anyway to translate it to a base 62? Example: echo convert(12324324); // returns Yg3 (fantasy example here) PHP's base_convert() can convert up to base 36.
dynamic
  • 46,985
  • 55
  • 154
  • 231
33
votes
6 answers

MySQL - Select only numeric values from varchar column

Consider the following table : create table mixedvalues (value varchar(50)); insert into mixedvalues values ('100'), ('ABC100'), ('200'), ('ABC200'), ('300'), ('ABC300'), ('400'), ('ABC400'), ('500'), ('ABC500'); How can I write a select…
Wes
  • 894
  • 1
  • 7
  • 17
32
votes
7 answers

How to check if NSString is contains a numeric value?

I have a string that is being generate from a formula, however I only want to use the string as long as all of its characters are numeric, if not that I want to do something different for instance display an error message. I have been having a look…
C.Johns
  • 10,185
  • 20
  • 102
  • 156
31
votes
2 answers

How to limit iOS keyboard to numeric input

The question pretty much says it all. Is there any way to have the iOS/iPhone keyboard default to numeric input?
Jack BeNimble
  • 35,733
  • 41
  • 130
  • 213
30
votes
5 answers

byte[] to unsigned BigInteger?

Motivation: I would like to convert hashes (MD5/SHA1 etc) into decimal integers for the purpose of making barcodes in Code128C. For simplicity, I prefer all the resulting (large) numbers to be positive. I am able to convert byte[] to BigInteger in…
Doochz
  • 1,039
  • 2
  • 14
  • 25
30
votes
4 answers

Why does the xor operator on two bytes produce an int?

//key & hash are both byte[] int leftPos = 0, rightPos = 31; while(leftPos < 16) { //possible loss of precision. required: byte, found: int key[leftPos] = hash[leftPos] ^ hash[rightPos]; …
defectivehalt
  • 2,462
  • 3
  • 21
  • 22
29
votes
3 answers

3.days.ago, 2.hours.from_now etc without Rails?

Some book mentioned some gem to decorate numbers with #days, #megabytes, #minutes etc. Is this only in ActiveSupport, or is there a smaller gem that provides this functionality for use in (small) non-rails gems? I want to use this functionality as…
d11wtq
  • 34,788
  • 19
  • 120
  • 195
29
votes
4 answers

C# - Numeric Suffixes

Possible Duplicate: Declaration suffix for decimal type Hey everyone, In the following snippet of code; RewardValue is a decimal: dto.RewardValue = 1.5; Now, this gives me the following error: "Cannot convert source type double to target type…
Jim B
  • 8,344
  • 10
  • 49
  • 77
29
votes
4 answers

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

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::infinity(); I guess the rationale behind it is that usually integral types have no values designated for…
legends2k
  • 31,634
  • 25
  • 118
  • 222
29
votes
11 answers

How to convert integer number into binary vector?

How to convert an integer number into binary vector using R? For example : number <- 11 [1] 1 0 1 1 what is the fastest possible method of conversion (using R code or some existing functions from packages) if I need to convert whole vector of…
Qbik
  • 5,885
  • 14
  • 62
  • 93