class Trig
const mod as float = 0.0174532925199433f #0.0174532925199432957692369076848861271344287188854172f
var time as System.Diagnostics.Stopwatch = System.Diagnostics.Stopwatch()
var file as String[] = File.readAllLines('trig.in')
var input as float[] = float[](1)
var sin_out as float[] = float[](1)
var cos_out as float[] = float[](1)
var tan_out as float[] = float[](1)
def main
.compute(@[1f])
.time.reset
.input = float[](.file.length)
.sin_out = float[](.file.length)
.cos_out = float[](.file.length)
.tan_out = float[](.file.length)
for num, line in .file.numbered, .input[num] = float.parse(line)
.time.start
.compute(.input)
.time.stop
for num in .file.length, .file[num] = (.sin_out[num].toString('0.000000E+0') + ' ' + .cos_out[num].toString('0.000000E+0') + ' ' + .tan_out[num].toString('0.000000E+0'))
File.writeAllLines('trig.out', .file)
print .time.elapsed
def compute(list as float[])
for index.sin_out in= float[](list.length)
.cos_out = float[](list.length)
degrees as float .tan_out = list[index]float[](list.length)
.time.start
#add `degrees %= 360` for numbers greaterindex thanin 360list.length
sindegrees as float = .sin(degrees)list[index]
cos#add as`degrees float%= =360` (1for -numbers (singreater *than sin)).sqrt360
* ((degrees - 180).abs - 90).sign
rad as float = sin as iffloat cos.isNaN,= cosdegrees =* 0.mod
.tan_out[index]two =as Math.round((sinfloat /= cos)rad * 10000000) / 10000000rad
.sin_out[index]sin -= Math.round(sinrad **= 10000000two) / 100000006
.cos_out[index]sin =+= Math.round(cosrad **= 10000000two) / 10000000120
def sin(degrees as float) as float
sin -= (rad *= radtwo) as/ float5040
= sin as float = degrees * .mod
sin += (rad *= two) as/ float362880
= rad * rad
sin -= (rad *= two) / 639916800
sin += (rad *= two) / 1206227020800
sin -= (rad *= two) / 50401307674368000
sin += (rad *= two) / 362880355687428096000
sin -= (rad *= two) / 39916800121645100408832000
sin += (rad *= two) / 622702080051090942171709440000f
sin -= (rad *= two) / 130767436800025852016738884976640000f
sin += (rad *= two) / 35568742809600015511210043330985984000000f
sin -= (rad *= two) / 12164510040883200010888869450418352160768000000f
sin += (rad *= two) / 51090942171709440000f8841761993739701954543616000000f
sin - cos as float = (rad1 *=- two(sin * sin)).sqrt /* 25852016738884976640000f((degrees - 180).abs - 90).sign
sin += if cos.isNaN, cos = 0
.tan_out[index] = Math.round(rad(sin *=/ twocos) * 10000000) / 15511210043330985984000000f10000000
sin - .sin_out[index] = Math.round(radsin *=* two10000000) / 10888869450418352160768000000f10000000
sin += .cos_out[index] = Math.round(radcos *=* two10000000) / 8841761993739701954543616000000f10000000
return sin.time.stop
The 360 * 10000 test used by the C answer runs in 370ms365ms (vs 190ms)
The 4-entry test used by the Python and Java answers runs in 0.32µs (vs 30µs, 3µs)
The 1000 random angle test used by the Fortran answer runs at 100ns per angle (vs 10µs)