Trigonometric functions: Difference between revisions
→{{header|Kotlin}}: made the Kotlin example not use Java
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:
=={{header|Kotlin}}==
<syntaxhighlight lang="
fun main() {
fun Double.toDegrees() = this * 180 / PI
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)
println("asin(sin(angle)) = $asin rad = ${asin.toDegrees()}°")
▲ val radians = Math.PI / 4.0
val
println("acos(cos(angle)) = $acos rad = ${acos.toDegrees()}°")
val
println("atan(tan(angle)) = $atan rad = ${atan.toDegrees()}°")
}</syntaxhighlight>
{{out}}
<pre>
angle = 0.7853981633974483 rad = 45.0°
sin(angle) = 0.7071067811865475
cos(angle) = 0.7071067811865476
tan(angle) = 0.9999999999999999
asin(sin(angle)) = 0.7853981633974482 rad = 44.99999999999999°
acos(cos(angle)) = 0.7853981633974483 rad = 45.0°
atan(tan(angle)) = 0.7853981633974483 rad = 45.0°
</pre>
|