Your job is to write a program to find the closest number to PI
.
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 PI
. For Integer
s, this would be 3
. Not 4
; 3
.
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.
Float
orDouble
is recommended. - Your program will generate a number
ctp
for "close toPI
" (I am just calling it that; you don't have to).223/71
<ctp
<22/7
must be true (this is why you can't chooseInteger
s). Also,ctp
must be the closet number toPI
in 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
ctp
. - 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 pi
th 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.