Trigonometric functions: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added internal flag, marked p2js compatible, PI now recognised/syntax coloured as a builtin constant)
(→‎{{header|Kotlin}}: made the Kotlin example not use Java)
Line 2,069: Line 2,069:


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<syntaxhighlight lang="scala">// version 1.1.2
<syntaxhighlight lang="kotlin">import kotlin.math.*


fun main() {
import java.lang.Math.*
fun Double.toDegrees() = this * 180 / PI
val angle = PI / 4
println("angle = $angle rad = ${angle.toDegrees()}°")
val sine = sin(angle)
println("sin(angle) = $sine")
val cosine = cos(angle)
println("cos(angle) = $cosine")
val tangent = tan(angle)
println("tan(angle) = $tangent")
println()


val asin = asin(sine)
fun main(args: Array<String>) {
println("asin(sin(angle)) = $asin rad = ${asin.toDegrees()}°")
val radians = Math.PI / 4.0
val degrees = 45.0
val acos = acos(cosine)
println("acos(cos(angle)) = $acos rad = ${acos.toDegrees()}°")
val conv = Math.PI / 180.0
val f = "%1.15f"
val atan = atan(tangent)
println("atan(tan(angle)) = $atan rad = ${atan.toDegrees()}°")
var inverse: Double
println(" Radians Degrees")
println("Angle : ${f.format(radians)}\t ${f.format(degrees)}\n")
println("Sin : ${f.format(sin(radians))}\t ${f.format(sin(degrees * conv))}")
println("Cos : ${f.format(cos(radians))}\t ${f.format(cos(degrees * conv))}")
println("Tan : ${f.format(tan(radians))}\t ${f.format(tan(degrees * conv))}\n")
inverse = asin(sin(radians))
println("ASin(Sin) : ${f.format(inverse)}\t ${f.format(inverse / conv)}")
inverse = acos(cos(radians))
println("ACos(Cos) : ${f.format(inverse)}\t ${f.format(inverse / conv)}")
inverse = atan(tan(radians))
println("ATan(Tan) : ${f.format(inverse)}\t ${f.format(inverse / conv)}")
}</syntaxhighlight>
}</syntaxhighlight>


{{out}}
{{out}}
<pre>
<pre>
angle = 0.7853981633974483 rad = 45.0°
Radians Degrees
sin(angle) = 0.7071067811865475
Angle : 0.785398163397448 45.000000000000000
cos(angle) = 0.7071067811865476

tan(angle) = 0.9999999999999999
Sin : 0.707106781186548 0.707106781186548
Cos : 0.707106781186548 0.707106781186548
Tan : 1.000000000000000 1.000000000000000


asin(sin(angle)) = 0.7853981633974482 rad = 44.99999999999999°
ASin(Sin) : 0.785398163397448 44.999999999999990
acos(cos(angle)) = 0.7853981633974483 rad = 45.0°
ACos(Cos) : 0.785398163397448 45.000000000000000
atan(tan(angle)) = 0.7853981633974483 rad = 45.0°
ATan(Tan) : 0.785398163397448 45.000000000000000
</pre>
</pre>