Skip to main content

Questions tagged [numbers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
4 votes
3 answers
5k views

When is a number a magic number?

Over the last couple of months I have been diving into coding standard IfSQ. As a part of this IfSQ standard, a rule is to not use Magic Numbers. While I don't have a problem with building this rule ...
5 votes
2 answers
505 views

Trivially Sortable Encoding for Arbitrary-Precision Decimals

I'm looking for a reasonably(*) space-efficient way to encode arbitrary-precision decimals (e.g. BigDecimal), such that when sorting the bit-pattern of the encodings lexicographically, the numbers ...
0 votes
4 answers
549 views

Why is it an issue that it takes 2 digits to represent the number 10 in decimal? [closed]

So we use hexadecimal which has the advantage of going up to 15 in single digits A-F, but why is it an issue that it takes 2 digits to represent the number 10 in decimal? I was reading up about ...
16 votes
4 answers
4k views

How to identify unstable floating point computations?

In numerics, it is very important to be able to identify unstable schemes and to improve their stability. How to identify unstable floating point computations? I am working on a very complex ...
0 votes
1 answer
901 views

How many ALU additions are needed to add three numbers?

Please give reasons for your answer. As I found, two additions are needed. This is because every number to be add needs to changed to binary. Then addition is done between two binary numbers where ...
36 votes
1 answer
3k views

Where does paypal's 92233720368547800 number come from? [closed]

There has been a story in the news about a man whose Paypal account was accidentally credited with $92,233,720,368,547,800. Where does this number come from? What sort of programming bug is likely to ...
4 votes
5 answers
3k views

sets of numbers that sum to a certain number?

I was asked this in an interview, and I'm not sure what the answer is or how to approach the problem. Find a pair of numbers that sum up to zero (or any other number), then find three (and then ...
1 vote
1 answer
2k views

Sum of divisors of numbers of the range ~ 10^6

I was trying to find the sum of divisors of numbers upto 106. The test cases are like of the order of 105. I have done some pre processing like int divisors(int num) { int sum=0; for(int i=1;...
10 votes
7 answers
15k views

Why are there so many numeric types (bit, int, float, double, long)?

I've learned PHP, Java, and C. Now I'm curious as to why there are so many types of numerical data types like bit, int, float, double, and long. Why not make only one type for numericals? Is there ...
0 votes
2 answers
326 views

Algorithm for picking reasonable min/max vals given a single value

I am making a simplistic in-browser IDE for some very domain-specific coding. Because I like Bret Victor's thoughts on Learnable Programming so much I thought I'd throw in some draggable numbers ala ...
10 votes
3 answers
512 views

Why is the minimum value of ints, doubles, etc 1 farther from zero than the positive value?

I know it has something to do with 2's complement and adding 1, but I don't really get how you can encode one more number with the same amount of bits when it comes to negative numbers.
2 votes
1 answer
722 views

Filling array with numbers from given range so that sum of adjacent numbers is square number

Problem: Fill all the cells using distinct numbers from <1,25> set, so that sum of two adjacent cells is a square number. (source: http://grymat.im.pwr.wroc.pl/etap1/zad1etp1213.pdf; numbers 20 ...
2 votes
2 answers
431 views

Which numeral systems are useful in computer science?

I am wondering which numeral system different programmers are using, or would use if their language has support for them. As an example, in C++ we can use: Octal by prefixing with 0 (e.g. 0377) ...
28 votes
6 answers
18k views

Why don't computers store decimal numbers as a second whole number?

Computers have trouble storing fractional numbers where the denominator is something other than a solution to 2^x. This is because the first digit after the decimal is worth 1/2, the second 1/4 (or 1/...
5 votes
2 answers
16k views

binary representation in Python and keeping leading zeros

I wanted to use the base64 Python library to encode a sequence of binary digits into base 64. Would it be possible to do it without converting to a string? If not, what is the best way to do it, ...
3 votes
3 answers
3k views

In programming light, what is special about the number 1223? [closed]

Just came across this post on reddit, where someone was charged $1,223 for a "FREE STEAK SALAD". I was trying to figure out 'Why 1223?' thinking that this might be a programming error somewhere. But ...
22 votes
3 answers
20k views

How can I properly compare double values for equality in a unit test?

I recently designed a time series module where my time series is essentially a SortedDictionnary<DateTime, double>. Now I would like to create unit tests to make sure that this module is always ...
10 votes
8 answers
2k views

A good schema to represent integer numbers from 0 to infinity, assuming you have infinite linear binary storage?

I would like a schema to represent integer numbers starting with 0, without any limit (assuming access to infinite linear storage). Here's a schema that can represent numbers from 0 to 255: Use the ...
2 votes
3 answers
341 views

What implementation do you use when dealing with operators in .Net?

My question is in a sense a follow up of this post on Time Series in .Net. Ideally, you would like to expand the basic TimeSeries<T> class by something like NumericTimeSeries<T>, where ...
12 votes
6 answers
4k views

any document which says exactly what range of numbers are .NET BigIntegers designed for?

I'm playing around with the .NET BigInteger and basically I'm wondering what number --an estimated answer would be fine-- is the point of deviation of the curve of (the graph of (increase of time ...
1 vote
3 answers
213 views

Does printing out numbers involve converting the numbers into characters?

In programming languages, when numbers (either integer, or real) are printed out, are they firstly converted to the codes of the readable characters that are meant to represent the numbers, and then ...
14 votes
2 answers
16k views

Why '42' is the preferred number when indicating something random?

I have seen this on the SO on many times. Whenever a question is vague and the question is asking some magical answer somebody or the other leaves a comment saying answer is 42. Even a book I am ...

1
2