mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 04:30:03 +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) },
|
"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) },
|
"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) },
|
"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) },
|
"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) },
|
"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) },
|
"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_ATAN(72),
|
||||||
FUNC_LN(73),
|
FUNC_LN(73),
|
||||||
FUNC_LOG2(74),
|
FUNC_LOG2(74),
|
||||||
FUNC_LOG10(75),
|
|
||||||
FUNC_SQRT(76),
|
FUNC_SQRT(76),
|
||||||
FUNC_RAD(77),
|
FUNC_RAD(77),
|
||||||
FUNC_DEG(78),
|
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_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_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_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_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_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())))
|
Syscall.FUNC_DEG -> evalstack.push(Value(DataType.FLOAT, Math.toDegrees(evalstack.pop().numericValue().toDouble())))
|
||||||
|
@ -502,14 +502,11 @@ atan(x)
|
|||||||
Arctangent.
|
Arctangent.
|
||||||
|
|
||||||
ln(x)
|
ln(x)
|
||||||
Natural logarithm (base E).
|
Natural logarithm (base e).
|
||||||
|
|
||||||
log2(x)
|
log2(x)
|
||||||
Base 2 logarithm.
|
Base 2 logarithm.
|
||||||
|
|
||||||
log10(x)
|
|
||||||
Base 10 logarithm.
|
|
||||||
|
|
||||||
sqrt(x)
|
sqrt(x)
|
||||||
Square root.
|
Square root.
|
||||||
|
|
||||||
|
@ -861,23 +861,32 @@ func_tan .proc
|
|||||||
.pend
|
.pend
|
||||||
|
|
||||||
func_atan .proc
|
func_atan .proc
|
||||||
rts
|
; -- push atan(f) back onto stack
|
||||||
.warn "atan not implemented"
|
jsr pop_float_fac1
|
||||||
|
stx SCRATCH_ZPREGX
|
||||||
|
jsr c64.ATN
|
||||||
|
jmp push_fac1_as_result
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
func_ln .proc
|
func_ln .proc
|
||||||
rts
|
; -- push ln(f) back onto stack
|
||||||
.warn "ln not implemented"
|
jsr pop_float_fac1
|
||||||
|
stx SCRATCH_ZPREGX
|
||||||
|
jsr c64.LOG
|
||||||
|
jmp push_fac1_as_result
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
func_log2 .proc
|
func_log2 .proc
|
||||||
rts
|
; -- push log base 2, ln(f)/ln(2), back onto stack
|
||||||
.warn "log2 not implemented"
|
jsr pop_float_fac1
|
||||||
.pend
|
stx SCRATCH_ZPREGX
|
||||||
|
jsr c64.LOG
|
||||||
func_log10 .proc
|
jsr c64.MOVEF
|
||||||
rts
|
lda #<c64.FL_LOG2
|
||||||
.warn "log10 not implemented"
|
ldy #>c64.FL_LOG2
|
||||||
|
jsr c64.MOVFM
|
||||||
|
jsr c64.FDIVT
|
||||||
|
jmp push_fac1_as_result
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
func_sqrt .proc
|
func_sqrt .proc
|
||||||
@ -909,7 +918,7 @@ func_deg .proc
|
|||||||
_one_over_pi_div_180 .byte 134, 101, 46, 224, 211 ; 1 / (pi * 180)
|
_one_over_pi_div_180 .byte 134, 101, 46, 224, 211 ; 1 / (pi * 180)
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
func_round .proc ; @todo check outcome vs floor/ceil
|
func_round .proc
|
||||||
jsr pop_float_fac1
|
jsr pop_float_fac1
|
||||||
stx SCRATCH_ZPREGX
|
stx SCRATCH_ZPREGX
|
||||||
jsr c64.FADDH
|
jsr c64.FADDH
|
||||||
@ -920,6 +929,7 @@ func_round .proc ; @todo check outcome vs floor/ceil
|
|||||||
sta ESTACK_LO,x
|
sta ESTACK_LO,x
|
||||||
dex
|
dex
|
||||||
rts
|
rts
|
||||||
|
.warn "round check outcome"
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
func_floor .proc ; @todo check outcome vs round/ceil
|
func_floor .proc ; @todo check outcome vs round/ceil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user