numbers

Generating the partitions of a number

I needed an algorithm to generate all possible partitions of a positive number, and I came up with one (posted as an answer), but it's exponential time. The algorithm should return all the possible ways a number can be expressed as the sum of positive numbers less than or equal to itself. So for example for the number 5, the result woul...

Increasing the maximum number of tcp/ip connections in linux

Hi all, I'm not sure if this is an OS, router, or ISP question, but I believe it is an OS question. Question: How can I increase the number of connections my computer can use? I'm using ubuntu. I currently have a lot of connections for bit torrent, but I'm not able to make full use of my entire download bandwidth. My BT client is ...

Fastest way to clamp a real (fixed/floating point) value?

Hi, Is there a more efficient way to clamp real numbers than using if statements or ternary operators? I want to do this both for doubles and for a 32-bit fixpoint implementation (16.16). I'm not asking for code that can handle both cases; they will be handled in separate functions. Obviously, I can do something like: double clampedA; ...

XSL: Formatting numbers, excluding trailing zeroes

Hi, first time SO user :) I know that I can format a number like this: format-number($value, '###,###.00') But I would like to remove the dot and the zeroes if $value is zero. So, 37368 -> 37,368 2.666667 -> 2.66 Is this possible using just number formatting (doesn't seem like it) or do I have to do something along the lines of ...

How do you generate a random number in Assembly language using the FASM compiler?

Hey guys, I'm really new to assembly and I'm trying to create a simple program. For this I need to generate a random number. Anybody know how I can do this with the FASM compiler? Thanks, Sam ...

Why do most languages not allow binary numbers?

Why do most computer programming languages not allow binary numbers to be used like decimal or hexadecimal? In VB.NET you could write a hexadecimal number like &H4 In C you could write a hexadecimal number like 0x04 Why not allow binary numbers? &B010101 0y1010 Bonus Points!... What languages do allow binary numbers? Edit Wo...

Is there a way to Convert Number words to Integers? Python

I need to convert 'one' into '1' 'two' into '2' and so on. Is there a way to do this a library or a class or anything? ...

What is the PayPal "amount" format in WPS?

What is the allowed format for PayPal's Website Payments Standard (WPS) forms in the "amount" field? Must the decimal point be ".", or is it currency-dependant? Must there always be exactly two decimal places, or can there also be three (for currencies that have such small nominations) or none (for currencies that have hyper-inflation)? ...

Extract decimal part from a floating point number in C

How can we extract the decimal part of a floating point number and to store the decimal part and the integer part into seperate two integer variables? ...

Why does toPrecision return a String?

View this code: function testprecision(){ var isNotNumber = parseFloat('1.3').toPrecision(6); alert(typeof isNotNumber); //=> string } I would have expected a number. If 'isNotNumber' should be a real number, recasting is the solution: alert(typeof parseFloat(isNotNumber)) //=> number [Edit] thanks for your answers. Precisi...

Print leading zeros with C++ output operator (printf equivalent)?

How can I format my output in C++? In other words, what is the C++ equivalent to the use of printf like this: printf("%05d", zipCode); I know I could just use printf in C++, but I would prefer the output operator <<. Would you just use the following? std::cout << "ZIP code: " << sprintf("%05d", zipCode) << std::endl; ...

check what number a string ends with in C++

In a C++ MD2 file loader, I have a lot of frames, each with a name that ends with a number, such as stand0 stand1 stand2 stand3 stand4 ... stand10 stand11 run0 run1 run2 etc. How do I get what the string is without the number behind? e.g. a function that changed "stand10" to just "stand" ...

Best method of generating a number with 256 random bits?

What is the best method of generating a number with 256 random bits? Does concatenating random bytes work? byte[] data = new byte[32]; RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); rng.GetNonZeroBytes(data); // should include zero bytes? string number = BitConverter.ToString(data, 0).Replace("-", ""); Further more, ...

Integer with leading zeroes

when i write System.out.println(0123); i get 83 however System.out.println((int)0123F); returns 123 why it works that way? ...

Building a "complete" number range w/out overlaps

Hey, I need to build a full "number range" set given a series of numbers. I start with a list such as : ID START * 0 a 4 b 70 c 700 d 701 e 85 where "def" is the default range & should "fill-in" the gaps "overlaps" are value (70, 700, 701) in starting data And need the following result: ID ST...

NSTimeInterval to readable NSNumber

NSTimeInterval == double; (e.g. 169.12345666663) How can I round up this double so that there are only 2 digits left after the "dot"? It would be very good if the result is a NSNumber. ...

Oracle: Pattern for to_char(number) to add additional ascii characters?

Using the Oracle to_char(number) function, is it possible to append ascii characters to the returned string? Specifically, I need to add a percentage character to the returned string. "select to_char(89.2244, '999G999G999G999G990D00') from dual" --> returns "89.22". I need a format pattern that returns "89.22%". I am using this throug...

Getting the local iPhone number through SDK

I am looking for a SDK API to retrieve the device's local phone number from the SIM card. Is there a way to do it? Thanks. Mike ...

What's a c# regular expression that'll validate currency, float or integer

I need a regex suitable for c# that'll validate a number if it matches: $1,000,000.150 $10000000.199 $10000 1,000,000.150 100000.123 10000 or the negative equivalents Anyone able to help? ...

Firebird determine if a string is all numbers

I have a VARCHAR field in a Firebird 2.0 table that can contain alphanumeric characters. I need to sort data on this field, sorting all values that contain only numbers as numbers, and sort all other values as 0. For example, if I have four values, "1", "2", "10", "string", I need to sort it as "string", "1", "2", "10". Default sort with...