Skip to main content

Questions tagged [numbers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
6 votes
4 answers
487 views

Why is there (practically) no 6-byte integer in common usage?

In Postgres, it used to be quite common to use a 4-byte integer auto field for primary keys, until it started becomming somewhat common to run into the 2147483647 limit of 4-byte integers. Now, it's ...
-1 votes
5 answers
2k views

Why are magic numbers bad practice?

Why are magic NUMBERS considered bad practice? For example: memcpy(ResourcesDir+GameDirLen, "/Resources", 11); What is wrong with the 11? Why are magical numbers so bad? Please, my question ...
13 votes
1 answer
1k views

Which was the first language to allow underscore in numeric literals?

Java 7+ allows to use underscores in numeric literals,which do not affect the value of the literal, yet are useful for grouping. Examples from the Java 7 documentation, entitled "Underscores in ...
48 votes
4 answers
11k views

Are there numbers that are not representable in base 10 but can be represented in base 2?

C# has the decimal type which is used for numbers that needs exact representation in base 10. For instance, 0.1 cannot be represented in base 2 (e.g. float and double) and will always be an ...
-4 votes
4 answers
265 views

Number system conversion

Why can't we directly convert octal number to base 8 to hexadecimal base 16 directly ? We can convert to octal by first converting it into binary equivalent, or by converting it to decimal equivalent ....
2 votes
2 answers
1k views

Why are floats called "real numbers" in some languages?

Some programing languages, notably Pascal, have a type of numbers called "real". However, mathematically speaking, these types aren't real. For them to be "real", these types have to be able to ...
1 vote
5 answers
6k views

Generate unique integer from two integers with algorithm

I am currently trying to come up with an algoritm which would take at least two numbers (say user IDs) and then come up with an unique number which is generated based on these two numbers. Each ...
9 votes
2 answers
25k views

complex numbers in programming?

Are complex numbers used in programming? If they are what is their significance? What IDEs and languages use them? And would it be recommended to learn how to implement them for a programming job (if ...
231 votes
8 answers
300k views

When do you use float and when do you use double

Frequently, in my programming experience, I need to make a decision whether I should use float or double for my real numbers. Sometimes I go for float, sometimes I go for double, but really this feels ...
17 votes
9 answers
16k views

Find a "hole" in a list of numbers

What is the fastest way to find the first (smallest) integer that doesn't exist in a given list of unsorted integers (and that is greater than the list's smallest value)? My primitive approach is ...
7 votes
2 answers
1k views

Why are angles usually represented by floats in programming?

My idea is that, if an unsigned 32-bit integer is used for representing angles in a way that 0 is 0°, 231 is 180° and 232−1 is just under 360°, all possible values are used and evenly distributed ...
0 votes
3 answers
533 views

What is this numeral system notation?

I used Google search to convert numbers from one numeral system to another. 10 to binary is 0b1010; 10 to hexadecimal is 0xA. What's the meaning of 'b' and 'x', accordingly? I think these are ...
0 votes
1 answer
128 views

What is the purpose of types which may be replaced by others?

In Kotlin or Java we have many different types: integer, byte, double, long, float, string, character, etc. But one can use an integer instead of byte, and a double instead of an integer. Why we need ...
1 vote
2 answers
3k views

The number of characters of hexadecimal numbers

0xF, 0x0000000F (total width is 10 characters), and 0x0000000000000000F (total width is 18 characters) all mean 15 (decimal). Is it correct to say that there is no reason to add leading zeros to a ...
-1 votes
1 answer
173 views

How can I efficiently find out if X is in any of N ranges of L-R numbers?

This is part of a bigger problem, which is to find out if point XYZ exists in any of n (XYZ -> XYZ) "boxes". I'm currently splitting up the problem into a smaller one, by focusing on one dimension ...
-4 votes
3 answers
783 views

If you had to represent a large number concisely would you use base 36 or ZZ?

According to Wikipedia: In mathematics and computing, hexadecimal (also base 16, or hex) is a positional system that represents numbers using a base of 16. Unlike the common way of representing ...
-2 votes
3 answers
806 views

How are floating point representations (say single precision for instance) able to represent more numbers than what a 32 bit memory allows?

I am trying to understand the floating point system. Can the floating-point system represent all the real numbers within the range of (10^38) accurately? If so, then how is it possible? Because ...
3 votes
2 answers
2k views

Should arbitrary numbers be stored as strings in a database?

I'm using Google as a login system for my latest project. So, my users table has a column named googleid, which stores Google's unique user id, which is a number, with a few dozen digits. For example, ...
30 votes
5 answers
8k views

What is the most efficient way to store a numeric range?

This question is about how many bits are required to store a range. Or put another way, for a given number of bits, what is the maximum range that can be stored and how? Imagine we want to store a ...
48 votes
2 answers
8k views

Why do some languages round to the nearest EVEN integer?

Programming languages like Scheme (R5RS) and Python (see this Question) round towards the nearest even integer when value is exactly between the surrounding integers. What is the reasoning behind ...
2 votes
1 answer
125 views

If you can store BigInts in a more optimal way than an array

This suggests just storing BigInts as an array: // n = -123 var n = { sign: -1, digits: [3, 2, 1] }; However, if you have "big ints", that array will get large: var n = { sign: -1, ...
0 votes
1 answer
2k views

Algorithm for base-conversion in C?

I put in this code which does what it's supposed to do, but perhaps there is a better or more general approach? I'm converting a 4-digit base 10 number e.g. "11" to base 16 e.g. "17" (which gets ...
2 votes
3 answers
319 views

Are all pseudo randomly generated numbers within a given period unique?

This will of course depend on the algorithm generating the pseudo random numbers, but what I'm wondering is whether practical, usable pseudo-random number generating algorithms exist that never repeat ...
17 votes
3 answers
65k views

Is there something special about the number 65535?

2¹⁶-1 & 2⁵ = 2⁵ (or? obviously ?) A developer asked me today what is bitwise 65535 & 32 i.e. 2¹⁶-1 & 2⁵ = ? I thought at first spontaneously 32 but it seemed to easy whereupon I thought ...
2 votes
1 answer
582 views

How does this function for calculating modular exponentiation work ?

I know that the rule in maths for modulus is this: ab mod n =(a mod n ) (b mod n) mod n I have found the following code for computing the modular exponentiation: pow(base,exponent,modulus){ if (...
5 votes
1 answer
987 views

how to stop denormals from messing up a real-time process (like an audio app or plug)

So there is an Intel page about what to do about denorms. (BTW, I know exactly what denormals are and am quite familiar with IEEE-754 floating point standard.) I have two questions: What are the ...
20 votes
7 answers
3k views

Why does Java have primitives for different size numbers?

In Java there are primitive types for byte, short, int and long and the same thing for float and double. Why is it necessary to have a person set how many bytes should be used for a primitive value? ...
28 votes
6 answers
117k views

How do random number generators work?

I was just pondering about php rand() function, and thinking about how I could remake it, and I came up completely stupified. How do random number generators work?
13 votes
9 answers
5k views

Why are unsigned numbers implemented?

I can't figure out why microprocessor systems implement unsigned numbers. I guess the cost is just double the number of conditional branches, since greater than, less than, .etc, need a different ...
2 votes
1 answer
1k views

BigDecimal for Calculation with and Display of Stock Shares and Prices?

I'm receiving flat files with the stock price and number of held shares for an account. One file contains the price and shares to 6 decimal places. The other file contains the price and shares to 12 ...
0 votes
1 answer
290 views

Encoding a signed number using a custom alphabet

When encoding a sequence of bits into a string (using an alphabet that is not yet known at compile time and with the goal that the resulting string is as short as possible and that this whole process ...
-2 votes
1 answer
3k views

What is 16 bit word's equivalent in decimal?

Question: For a 16 bit word with 6 bits for an opcode How many different instructions could I fit into the instruction set? What is the largest number that I could use as data? Answer:...
0 votes
1 answer
454 views

Combine sequences of numbers with "variable bitlengths" into short unique strings

It is not unlikely that what I want to do is not possible, but it doesn't hurt to ask. Imagine a set of lists, each containing positive integers (in my case, a list always consists of four integers, ...
86 votes
6 answers
20k views

Why are floats still part of the Java language when doubles are mostly recommended instead?

In every place I've looked, it says that double is superior to float in almost every way. float has been made obsolete by double in Java, so why is it still used? I program a lot with Libgdx, and ...
8 votes
1 answer
3k views

Exclusive upper bound in random number range

Why do languages' random number generators tend to return a value exclusive of the upper bound of the range? For example, an implicit range - JavaScript's random() method "Return a random number ...
9 votes
3 answers
57k views

What is the time complexity of the algorithm to check if a number is prime?

What is the time complexity of the algorithm to check if a number is prime? This is the algorithm : bool isPrime (int number) { if (number < 2) return false; if (number == 2) return ...
-1 votes
1 answer
1k views

Find missing number in sequence in string [closed]

I have a string that contains numbers in sequence. There are no delimiters between numbers. I have to find missing number in that sequence. For example: 176517661768 is missing the number: 1767 ...
52 votes
4 answers
20k views

Has Little Endian won?

When teaching recently about the Big vs. Little Endian battle, a student asked whether it had been settled, and I realized I didn't know. Looking at the Wikipedia article, it seems that the most ...
2 votes
4 answers
6k views

Understanding binary numbers in terms of real world objects [closed]

When I represent a number in the decimal system, I have an intuitive knowledge of what it amounts to. For example take the number '10': I understand that it means 10 apples or 10 people... i.e I can ...
4 votes
3 answers
3k views

Is there any programming language(s) which has mathematical number types? [closed]

I may not have worded the title correctly. Is there any programming language(s) which deals with natural mathematical number types rather than the typical data types we see like Int32, Int64, Float, ...
3 votes
2 answers
2k views

How widespread is the use of arabic numerals in Japanese and Chinese?

I'm localising a times-table app aimed at children. I understand that the Japanese and Chinese languages have a variety of ways to represent numbers. I also have read that, particularly with Japanese, ...
0 votes
2 answers
608 views

What is the best type to represent a number in java and why? [closed]

I am developing a dynamically typed, interpreted programming language, which is interpreted by a runtime written in Java. As Java is statically typed, I need to define how the numbers used in the ...
1 vote
2 answers
193 views

How to implement rounding in an all-purpose stack language using different types?

Disclaimer: If you are not terribly interested in numerics and mathematical processes, this is most likely nothing for you. I am currently a bit stuck in a development process of a private project I ...
0 votes
5 answers
1k views

Is String processing more complex than number processing in programming languages?

I feel that string processing is always more complex than Numbers or mathematical processing. Are our programming languages are designed this way that mathematical operations are pretty much straight ...
1 vote
3 answers
361 views

Generate random numbers with certain spikes? [duplicate]

I am trying to generate random numbers to simulate steering wheel angles and velocities of a car. So for steering wheels the random numbers could go like 1,2,4,6,4,3,40,0. I can generate random ...
51 votes
3 answers
81k views

Why is 2^16 a "special" number? [closed]

OK, I feel stupid asking this - but in Jeff's article: Getting the Interview Phone Screen Right and originally stated in the 5 essential phone screen questions: They shouldn't stare blankly at you ...
-5 votes
1 answer
122 views

Distributivity and Associativity for 32/64bit signed integers [closed]

I'm looking into 32/64bit signed integers and their algebraic properties. I am quite sure that the the three operators +, - and * fulfill the distributive and associative property (integer division ...
1 vote
3 answers
4k views

What is more efficient, a single square root or multiple divisions?

Say I make a program that calculates all possible (integral) factors of a certain number that has been input. Is it theoretically more efficient to check with all integers up to the square root of ...
53 votes
11 answers
19k views

Get 100 highest numbers from an infinite list

One of my friend was asked this interview question - "There is a constant flow of numbers coming in from some infinite list of numbers out of which you need to maintain a datastructure as to ...
0 votes
1 answer
514 views

Representing the hierarchy of groups of numbers using type inheritance

I've run into an interesting conundrum while coding my own implementations for the basic sets of mathematical numbers (Natural, Integer, Rational, Irrational, Real, Complex). I'm doing this mostly for ...