Number Analysis
In this tutorial we analyse different properties of numbers such as prime numbers, arbitrariliy sized decimals, and limit calculations. We want to give a rough overview of various properties of the natural numbers
with respect to several operations. This provides us with several nice examples where everything mentioned in the previous tutorials can be put to good use.
Limit Calculations
Write a single program for each of the following:
- L2: Given a data type such as float, double, char, int, long. Write a function for each of these data types to find the minimum and maximul value they can accommodate. Suppose the given limits in some include files do not consider the new computer architectures, such as AMD64.
- L2: Modify the previous program to determine the smallest difference between two numbers which can be represent by each of these data types, e.g. double resolution

- L3: What can happen, if we add
to
a million times. - L3: Which possibilities can be used to circumvent these issues?
Hint
- Why does the concept of finite numerics influence the handling of numbers inside the computer? What does the term "finite numerics" mean?
- Derive a monotonic function (monotonically increasing or monotonically decreasing) and iterate as long as the values are valid, e.g., no over or underflow. Link: monotonic function at wikipedia
- Consider of the fact, that the operations inside the computer do not necessarily fullfill the mathematical concepts of commutativity. Why not?
Prime Numbers
Write a single program for each of the following:
- L1: Read in an integer and output if this integer is a prime number or not. Remark: a prime number is a natural number that can be divided by exactly two natural numbers: 1 and the prime number itself.
- L2: Read in an integer and determine the prime factors of this given number. First, check if the entered number is a prime number.
- L2: Write a program to analyse Goldbach's conjecture (every even integer greater than 2 can be written as the sum of two primes). Read in an even integer and print the two prime numbers. Question: is this decomposition unique?
- L3: Prime numbers can be used to generate a (seemingly) random sequence of numbers (pseudo-random number generator). To do so, we start with a prime number
and check if
is a prime number as well. In such a case
is called a Sophie Germain prime. The first
single digits of the result of
represent a pseudo-random sequence of numbers. Print each of the valid digits.
An example using q = 23 generates the random digits 0,4,3,4,7,8,2,6.....3,9,1,3.