Skip to main content
8 of 10
added 93 characters in body
user avatar
user avatar

Fast Trig [sandboxing]

THIS QUESTION IS NOT FINISHED, PLEASE DO NOT POST ANSWERS UNTIL THIS MESSAGE IS REMOVED. UPVOTE AND REOPEN-VOTE IF YOU THINK IT'S READY TO START, COMMENT IF YOU SEE ANY PROBLEMS.

I am testing this sandbox system to see how it compares to the sandbox on the meta site.


Fast Trigonometry Calculations

Your task is to create a program which can calculate the sine, cosine and tangent of an angle in degrees.

Rules

  • No built-in trigonometry functions (not even secant, cosecant and cotangent if your language has them).
  • You may use lookup tables, but their total size must not exceed 3000 members (for all of the three operations put together). Please make it read the tables from a file (e.g. trig.lookup) so they don't confuse the code.
  • No network access.
  • You must correctly round your output as explained below. Don't use floor or ceiling.
  • You may use any method to calculate the values, for example continued fractions, as long as it is correct to 7 significant figures.
  • Your code must be able to time itself. Exclude the file I/O operations from your time - so just time the function(s) that do(es) the trig and any rounding.
  • I must be able to run your code. Please post a link to a freely available compiler/interpreter and give the instructions needed to compile/run the code (e.g. what options to pass to GCC).
  • Standard loopholes apply.

Input Format

  • Read from a file called trig.in unless your language doesn't support file I/O.
  • Angles are between 0 and 360 inclusive.
  • Input will consist of angles to ten significant figures in decimal digits, separated by new lines. For example:

90.00000000
74.54390000
175.5000000

Output Format

  • For each angle supplied, you must output its sine, cosine and tangent to 7 significant figures, separated by spaces, on a single line. Use "scientific notation", e.g. 1.745329E-5 for tan 0.001 or 1.000000E+0 for sin 90.
  • Denote infinity or NaN by n, for example the output for 90.00000000 should be 1.000000 0.000000 n.
  • If the input is three angles separated by newlines, your output should consist of three lines, each containing the sine, cosine and tangent.
  • You may not output anything else.
  • Output to a file called trig.out unless your language does not support file I/O.

Scoring

  • . The challenge is to write a program which computes these three values as quickly as possible. Fastest time wins.
  • Everyone will receive the same test input of many angles.
  • Times will be recorded on my machine.
  • Your score is the average of three runs on the same input (you can't save anything in between runs obviously).
  • Compiling time not included. This challenge is more about the method used than the language. (If someone could point me to how I would exclude compilation time for languages such as Java, I'd be very grateful)
  • My machine is an Ubuntu 14.04 install. The processor's stats are on Pastebin (obtained by running cat /proc/cpuinfo).
  • I will edit your time into your answer when I've tested it.

THIS QUESTION IS NOT FINISHED, PLEASE DO NOT POST ANSWERS UNTIL THIS MESSAGE IS REMOVED. UPVOTE AND REOPEN-VOTE IF YOU THINK IT'S READY TO START, COMMENT IF YOU SEE ANY PROBLEMS.

user16402