Your job is to write a program to find the closest number to
Let me clarify.
You will first choose a number type. Let us say you choose
Integer (in an actual answer, you cannot). Your program would then have to generate an integer that is closed to
Integers, this would be
For every allowed number type, there will be one and only one closest number, as you will see.
- Select your number type. It should only be able to represent rational numbers. You can not make up your own number types.
- Your program will generate a number
ctpfor "close to
PI" (I am just calling it that; you don't have to).
22/7must be true (this is why you can't choose
ctpmust be the closet number to
PIin its number type (although see bonus).
- No importing libraries for mathematical functions, operations, etc... (although types are allowed as long, as it obeys #1).
- You must somehow output
- You also may not hard code any number (in any type) that uses at least half the precision of your chosen number type.
Bonus: If you use a data type with a precision that depends on machine resources, and it still generates the most accurate approximation possible for any given machine, you can take the
pith root of your score.
Note: If you code may actually exhaust machine resources, put a warning in. That way people know to use virtual machines to check it (or just check it with their minds).
This is code golf, so shortest program in bytes wins!
Note: The point of this challenge is not just to be another pi calculation challenge. You have to work at the limits of your number type, where all calculations can have detrimental rounding errors. You are doing maximum-precision computing. This is not the same as just outputting a large number of digits.