Skip to main content

Questions tagged [numbers]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
6 votes
4 answers
482 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 ...
orokusaki's user avatar
  • 1,093
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 ...
matj1's user avatar
  • 187
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 ...
floreapaun's user avatar
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 ...
user avatar
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 ...
user90726's user avatar
  • 205
-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 ...
user avatar
-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 ...
Shadowjonathan's user avatar
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 ...
David Tonhofer's user avatar
-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 ...
1.21 gigawatts's user avatar
-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 ...
Viper's user avatar
  • 29
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 ...
rghome's user avatar
  • 678
-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 ....
Zero001's user avatar
  • 19
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, ...
Lance Pollard's user avatar
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 ...
Peter Berg's user avatar
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 (...
user avatar
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 ...
robert bristow-johnson's user avatar
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 ...
jtw's user avatar
  • 155
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? ...
yitzih's user avatar
  • 993
0 votes
1 answer
288 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 ...
ceran's user avatar
  • 255
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 ...
James's user avatar
  • 285
-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:...
mertyildiran's user avatar
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, ...
ceaaj's user avatar
  • 3
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 ...
Eames's user avatar
  • 885
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, ...
markasoftware's user avatar
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 ...
John K's user avatar
  • 1,406
-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 ...
Neo's user avatar
  • 31
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, ...
nawfal's user avatar
  • 157
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, ...
glenstorey's user avatar
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 ...
vainolo's user avatar
  • 1,341
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 ...
Thorsten S.'s user avatar
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 ...
Aura's user avatar
  • 205
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 ...
zzzzz's user avatar
  • 227
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 ...
Purple Dragon's user avatar
-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 ...
Artemis's user avatar
  • 99
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 ...
Profpatsch's user avatar
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 ...
Tejas Ramdas's user avatar
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 ...
Mirrana's user avatar
  • 1,077
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 ...
Matthijs's user avatar
  • 167
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 ...
Niccolo M.'s user avatar
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 ...
Dexter's user avatar
  • 293
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 ...
Crizly's user avatar
  • 327
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 ...
Max's user avatar
  • 599
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 ...
Niklas Rosencrantz's user avatar
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 ...
user40989's user avatar
  • 2,930
0 votes
1 answer
900 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 ...
user2695507's user avatar
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 ...
shamp00's user avatar
  • 2,759
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;...
Prashant Singh's user avatar
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 ...
GusDeCooL's user avatar
  • 212
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 ...
MD. Mohiuddin Ahmed's user avatar
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 ...
Jakub Zaverka's user avatar