mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
min/max float
This commit is contained in:
parent
4c2a81c452
commit
85c65a9a9f
@ -13,7 +13,7 @@
|
||||
ubyte[4] uba = [4,200,10,15]
|
||||
word[4] wa = [400,-200,-1000,1500]
|
||||
uword[4] uwa = [4000,200,1000,150]
|
||||
float[4] fa = [-2.22, 3.33, -5.55, 1.11]
|
||||
float[6] fa = [-2.22, 3.33, -5.55, 1.11, 9999.99, -999.99]
|
||||
c64scr.print(" X=")
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
@ -26,8 +26,8 @@
|
||||
; word wmax = max(wa)
|
||||
; uword uwmin = min(uwa)
|
||||
; uword uwmax = max(uwa)
|
||||
; float fmin = min(fa)
|
||||
; float fmax = max(fa)
|
||||
float fmin = min(fa)
|
||||
float fmax = max(fa)
|
||||
|
||||
c64scr.print_b(bmin)
|
||||
c64.CHROUT(',')
|
||||
@ -46,10 +46,10 @@
|
||||
; c64scr.print_uw(uwmax)
|
||||
; c64.CHROUT('\n')
|
||||
;
|
||||
; c64flt.print_f(fmin)
|
||||
; c64.CHROUT(',')
|
||||
; c64flt.print_f(fmax)
|
||||
; c64.CHROUT('\n')
|
||||
c64flt.print_f(fmin)
|
||||
c64.CHROUT(',')
|
||||
c64flt.print_f(fmax)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print(" X=")
|
||||
c64scr.print_ub(X)
|
||||
|
@ -12,8 +12,8 @@ import kotlin.math.pow
|
||||
|
||||
|
||||
// 5-byte cbm MFLPT format limitations:
|
||||
const val FLOAT_MAX_POSITIVE = 1.7014118345e+38
|
||||
const val FLOAT_MAX_NEGATIVE = -1.7014118345e+38
|
||||
const val FLOAT_MAX_POSITIVE = 1.7014118345e+38 // bytes: 255,127,255,255,255
|
||||
const val FLOAT_MAX_NEGATIVE = -1.7014118345e+38 // bytes: 255,255,255,255,255
|
||||
|
||||
const val BASIC_LOAD_ADDRESS = 0x0801
|
||||
const val RAW_LOAD_ADDRESS = 0xc000
|
||||
|
@ -1206,9 +1206,37 @@ func_max_w .proc
|
||||
.pend
|
||||
|
||||
func_max_f .proc
|
||||
dex
|
||||
rts
|
||||
.warn "todo func_max_f"
|
||||
lda #<_min_float
|
||||
ldy #>_min_float
|
||||
jsr c64.MOVFM ; fac1=min(float)
|
||||
lda #255
|
||||
sta _cmp_mod+1 ; compare using 255 so we keep larger values
|
||||
_minmax_entry jsr pop_array_and_lengthY
|
||||
stx SCRATCH_ZPREGX
|
||||
dey
|
||||
sty SCRATCH_ZPREG
|
||||
- lda SCRATCH_ZPWORD1
|
||||
ldy SCRATCH_ZPWORD1+1
|
||||
jsr c64.FCOMP
|
||||
_cmp_mod cmp #255 ; will be modified
|
||||
bne +
|
||||
; fac1 is smaller/larger, so store the new value instead
|
||||
lda SCRATCH_ZPWORD1
|
||||
ldy SCRATCH_ZPWORD1+1
|
||||
jsr c64.MOVFM
|
||||
+ lda #5
|
||||
clc
|
||||
adc SCRATCH_ZPWORD1
|
||||
sta SCRATCH_ZPWORD1
|
||||
bcc +
|
||||
inc SCRATCH_ZPWORD1+1
|
||||
+ ldy SCRATCH_ZPREG
|
||||
dey
|
||||
sty SCRATCH_ZPREG
|
||||
bpl -
|
||||
jmp push_fac1_as_result
|
||||
_min_float .byte 255,255,255,255,255 ; -1.7014118345e+38
|
||||
.pend
|
||||
|
||||
pop_array_and_lengthY .proc
|
||||
@ -1276,9 +1304,13 @@ func_min_w .proc
|
||||
.pend
|
||||
|
||||
func_min_f .proc
|
||||
dex
|
||||
rts
|
||||
.warn "todo func_min_f"
|
||||
lda #<_max_float
|
||||
ldy #>_max_float
|
||||
jsr c64.MOVFM ; fac1=max(float)
|
||||
lda #1
|
||||
sta func_max_f._cmp_mod+1 ; compare using 1 so we keep smaller values
|
||||
jmp func_max_f._minmax_entry
|
||||
_max_float .byte 255,127,255,255,255 ; 1.7014118345e+38
|
||||
.pend
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user