Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Hello everyone I was going through a few programming questions and encounter one strange thing, The problem asked me to do some logic which is not relevant or nor I am asking the logic here, But the question involved the integers and said that I should keep in consideration that integer value be less than 10000000000
My doubt what data type to be used to store such ranges or, Lets just assume that some C program is used in some banking application which involves huge no of these magnitude, How do we store such huge no, Note: Even type 'long long' wont be able to store such huge no , Then how do we store such no ?
if possible use int64_t instead of long long that is defined in standard library header stdint.h. That holds 64 bit integers for sure. Larges number that can be represented is 2**63-1 and that is 9223372036854775807 (9e18). So it can hold 10000000000.
You could imagine the value stored in a database where numeric precision can be specified for data columns. But it's more likely that the particular value is specified to force you to think about how the algorithm or code would handle numeric overflow.
BTW, many systems use a 64 bit long long, which could hold the value you mention. Here's a great site to experiment with numbers and gain an intuitive feel for this:
http://www.wolframalpha.com/input/?i=2%5E64
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a problem in C, I am not allowed to use floats as the microcontroller it will be flashed does not support that data type. Now all my integers are being rounded off as it should. How do I handle this case?
A short research indicates using bit wise operation such as left shift and right shift. I know what are these operations. But I do not know how to use these operations to achieve what I want.
Another possibility is the Q number format.
You will get some results if you google "Q number format" or some variations.
It is often used for some DSP related topics in C. Here another blog post that explains that number format and here is an example code implementation for q-numbers in C.
In general you can say that q-numbers represent a number between -1 and 1 without using floating point arithmetic.
Normally a microcontroller don't have a floating point unit, everything works with integers. But its up to you which unit you like for your integers.
For example:
100 could be 100 cm or 1,00 m
1000 could be 100,0 cm or 1,000 m and so on..
Please have a look at the description:
electronic.stackexchange
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
From Python Numeric Types:
Integers have unlimited precision.
This test
#include <stdio.h>
int main(void) {
printf("%zu bytes", sizeof(long long));
return 0;
}
gives me 8 bytes or 64 bits under Linux.
How this is implemented in cpython (this was answered in the comment section)?
What happens when the integer exceeds long long in the implementation?
How big is the speed difference in arithmetics between pre-8-byte and post-8-byte integers?
What if I have a bigger number in Python (not going into 8 bytes)?
Python will adapt and always store the correct number, no approximation. Even with very big INTEGER (but this is not true with other types)
How is it stored in the system, literally? Like a few smaller integers?
That's python implementation. You could find it from the source code here : svn.python.org/projects/python/trunk/Objects/longobject.c (thanks #samgak)
Does it hugely slow down the arithmetics on this number?
Yes like in other languages when the number becomes bigger than .e.g 2^32 on 32 bits systems the arithmetic becomes slower. How much is implementation dependent.
What does Python do, when it encounters such number?
Huge integers are stored in a different way and all arithmetic is adapted to fit.
Is there any difference in Python's 2 & 3 behavior except storing as long in Python 2 and appending L to string representation?
Python 2 and 3 should have the same high level behaviour.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to hold a value of range 10^20 in C. Heard that the big int in C can hold such big values. How to declare and use the big int in C.
Does anybody know of an easy way to do that? Any help would really be appreciated!
You can use type unsigned long long, the range is at least 0..18446744073709551615, but that's only 1.8E19, so slightly less than what you need. If you really want to go beyond 64 bits, you can check if your system supports 128 bit integers (as type __int128, __int128_t, int128_t or something similar) or you will need a multi-precision package such as GMP.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Problem Statement
Addition is a very basic operation in mathematics. Jimmy was very weak in addition, so his father decided to teach him. Jimmy is given a number and has to perform addition on all the digits of that number till that the large number gets converted into a single digit. Your task is to prepare a program for him so that he can easily find out the final number.
Input Format
First line contains T (1<=T<=100) the number of test cases.
Each test case contains integer N (1<=N<=10^100).
Output Format
For each test case, output the one digit number by repeatedly adding the digits.
Constraints
1<=T<=100
1<=N<=10^500
I'd represent the very large input number as char, and the total of the digits (first pass) will easily fit in an int. You'll need a little more than simple arithmetic, but it shouldn't be difficult (case seems a likely way to manage the job).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
For Example : Can we increase the size of long long variable to store value of bigger size.(more than 64 bit)
If you are talking about compiler implementation: Yes, I think the C standard doesn't impose any upper bound, only minimums (like char is 8 bits or more) and limits on relative sizes (like, long can't be shorter than int). So you can set the size to anything in your own compiler (or a backend to an existing compiler), or provide command line switches to select it at compile time.
If you are asking from application programmers perspective: No, I don't know of a compiler which would support this. It would have the complication, that you would also need all libraries compiled with custom integer type sizes, because if library code expects a long to be 64 bits, and you call it with 128 bit long, there'll be trouble. At machine code level, there is no C type, there's just raw bytes in registers and memory, and the machine code just has to handle them right everywhere in the application and the librararies.
Perhaps you should ask a question about what you actually want to achieve, there is probably a solution. Use a bigint library? Use a compiler-specific non-standard large integer type? Use a struct or an array with several integers in it (a bigint library basically does this under the hood)? Use floating point? Use ascii text numbers?