mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
log functions
This commit is contained in:
parent
4be6a2eeef
commit
ca1d6bff56
@ -34,7 +34,6 @@ val BuiltinFunctions = mapOf(
|
||||
"atan" to FunctionSignature(true, listOf(BuiltinFunctionParam("rads", setOf(DataType.FLOAT))), DataType.FLOAT) { a, p, n, h -> oneDoubleArg(a, p, n, h, Math::atan) },
|
||||
"ln" to FunctionSignature(true, listOf(BuiltinFunctionParam("value", setOf(DataType.FLOAT))), DataType.FLOAT) { a, p, n, h -> oneDoubleArg(a, p, n, h, Math::log) },
|
||||
"log2" to FunctionSignature(true, listOf(BuiltinFunctionParam("value", setOf(DataType.FLOAT))), DataType.FLOAT) { a, p, n, h -> oneDoubleArg(a, p, n, h, ::log2) },
|
||||
"log10" to FunctionSignature(true, listOf(BuiltinFunctionParam("value", setOf(DataType.FLOAT))), DataType.FLOAT) { a, p, n, h -> oneDoubleArg(a, p, n, h, Math::log10) },
|
||||
"sqrt" to FunctionSignature(true, listOf(BuiltinFunctionParam("value", setOf(DataType.FLOAT))), DataType.FLOAT) { a, p, n, h -> oneDoubleArg(a, p, n, h, Math::sqrt) },
|
||||
"rad" to FunctionSignature(true, listOf(BuiltinFunctionParam("value", setOf(DataType.FLOAT))), DataType.FLOAT) { a, p, n, h -> oneDoubleArg(a, p, n, h, Math::toRadians) },
|
||||
"deg" to FunctionSignature(true, listOf(BuiltinFunctionParam("value", setOf(DataType.FLOAT))), DataType.FLOAT) { a, p, n, h -> oneDoubleArg(a, p, n, h, Math::toDegrees) },
|
||||
|
@ -33,7 +33,6 @@ enum class Syscall(val callNr: Short) {
|
||||
FUNC_ATAN(72),
|
||||
FUNC_LN(73),
|
||||
FUNC_LOG2(74),
|
||||
FUNC_LOG10(75),
|
||||
FUNC_SQRT(76),
|
||||
FUNC_RAD(77),
|
||||
FUNC_DEG(78),
|
||||
@ -1513,7 +1512,6 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
Syscall.FUNC_ATAN -> evalstack.push(Value(DataType.FLOAT, atan(evalstack.pop().numericValue().toDouble())))
|
||||
Syscall.FUNC_LN -> evalstack.push(Value(DataType.FLOAT, ln(evalstack.pop().numericValue().toDouble())))
|
||||
Syscall.FUNC_LOG2 -> evalstack.push(Value(DataType.FLOAT, log2(evalstack.pop().numericValue().toDouble())))
|
||||
Syscall.FUNC_LOG10 -> evalstack.push(Value(DataType.FLOAT, log10(evalstack.pop().numericValue().toDouble())))
|
||||
Syscall.FUNC_SQRT -> evalstack.push(Value(DataType.FLOAT, sqrt(evalstack.pop().numericValue().toDouble())))
|
||||
Syscall.FUNC_RAD -> evalstack.push(Value(DataType.FLOAT, Math.toRadians(evalstack.pop().numericValue().toDouble())))
|
||||
Syscall.FUNC_DEG -> evalstack.push(Value(DataType.FLOAT, Math.toDegrees(evalstack.pop().numericValue().toDouble())))
|
||||
|
@ -502,14 +502,11 @@ atan(x)
|
||||
Arctangent.
|
||||
|
||||
ln(x)
|
||||
Natural logarithm (base E).
|
||||
Natural logarithm (base e).
|
||||
|
||||
log2(x)
|
||||
Base 2 logarithm.
|
||||
|
||||
log10(x)
|
||||
Base 10 logarithm.
|
||||
|
||||
sqrt(x)
|
||||
Square root.
|
||||
|
||||
|
@ -861,23 +861,32 @@ func_tan .proc
|
||||
.pend
|
||||
|
||||
func_atan .proc
|
||||
rts
|
||||
.warn "atan not implemented"
|
||||
; -- push atan(f) back onto stack
|
||||
jsr pop_float_fac1
|
||||
stx SCRATCH_ZPREGX
|
||||
jsr c64.ATN
|
||||
jmp push_fac1_as_result
|
||||
.pend
|
||||
|
||||
func_ln .proc
|
||||
rts
|
||||
.warn "ln not implemented"
|
||||
; -- push ln(f) back onto stack
|
||||
jsr pop_float_fac1
|
||||
stx SCRATCH_ZPREGX
|
||||
jsr c64.LOG
|
||||
jmp push_fac1_as_result
|
||||
.pend
|
||||
|
||||
func_log2 .proc
|
||||
rts
|
||||
.warn "log2 not implemented"
|
||||
.pend
|
||||
|
||||
func_log10 .proc
|
||||
rts
|
||||
.warn "log10 not implemented"
|
||||
; -- push log base 2, ln(f)/ln(2), back onto stack
|
||||
jsr pop_float_fac1
|
||||
stx SCRATCH_ZPREGX
|
||||
jsr c64.LOG
|
||||
jsr c64.MOVEF
|
||||
lda #<c64.FL_LOG2
|
||||
ldy #>c64.FL_LOG2
|
||||
jsr c64.MOVFM
|
||||
jsr c64.FDIVT
|
||||
jmp push_fac1_as_result
|
||||
.pend
|
||||
|
||||
func_sqrt .proc
|
||||
@ -909,7 +918,7 @@ func_deg .proc
|
||||
_one_over_pi_div_180 .byte 134, 101, 46, 224, 211 ; 1 / (pi * 180)
|
||||
.pend
|
||||
|
||||
func_round .proc ; @todo check outcome vs floor/ceil
|
||||
func_round .proc
|
||||
jsr pop_float_fac1
|
||||
stx SCRATCH_ZPREGX
|
||||
jsr c64.FADDH
|
||||
@ -920,6 +929,7 @@ func_round .proc ; @todo check outcome vs floor/ceil
|
||||
sta ESTACK_LO,x
|
||||
dex
|
||||
rts
|
||||
.warn "round check outcome"
|
||||
.pend
|
||||
|
||||
func_floor .proc ; @todo check outcome vs round/ceil
|
||||
|
Loading…
Reference in New Issue
Block a user