Theres been quite some activity behind the scenes here, and this is what weve come up with: (All previous versions are abominations and embarrassments and should be withdrawn from active service immediately and taken behind the woodshed and shot!):

Code: Select all

`100 REMark ======================================================`

110 REMark Float to Hex by pjw & steven pool

120 REMark V0.02, December 3rd 2017

130 :

140 DEFine FuNction FLTp$(n)

150 LOCal x, m, s

160 IF n = 0: RETurn FILL$('0', 12)

170 IF n < 0: s = -1: m = -n: ELSE : s = 1: m = n

180 IF m > -$80000000 THEN

190 FOR x = $81F TO $FFF

200 m= m / 2

210 IF m < $40000000: EXIT x

220 END FOR x

230 m = m + m

240 ELSE

250 FOR x = $81F TO 0 STEP -1

260 IF s = -1: IF m <= $40000000: m = m + m: ELSE EXIT x

270 IF s = +1: IF m < $40000000: m = m + m: ELSE EXIT x

280 END FOR x

290 END IF

300 m = s * m

310 :

320 RETurn HEX$(x, 16) & HEX$(m, 32)

330 END DEFine FLTp$

340 :

The above shows something of whats going on, hence the inline hex. Howver, Qlib wont even discuss it,

so the below may be more suitable:

Code: Select all

`10 ovf = 2^30: ov2 = 2^31: REMark Overflow limits`

11 :

500 REMark ======================================================

510 REMark Float to Hex by Steve Pool & pjw

520 :

530 DEFine FuNction FLTs$(n)

540 LOCal x,m,s, x$(4), m$(8)

550 IF n=0: RETurn FILL$('0',12)

560 IF n<0: s=-1: m=-n

570 IF n>0: s=1 : m=n

580 IF m>ov2 THEN

590 FOR x=2079 TO 4095: m=m/2: IF m<ovf: EXIT x: END IF

600 m=m+m

610 ELSE FOR x=2079 TO 0 STEP -1

620 IF s=-1: IF m<=ovf: m=m+m: ELSE EXIT x: END IF

630 IF s=+1: IF m< ovf: m=m+m: ELSE EXIT x: END IF

640 END FOR x

650 END IF : m=s*m: x$=HEX$(x,16): m$=HEX$(m,32) : RETurn x$&m$

660 END DEFine

670 :

They both give correct answers for the whole range of floats (as far as weve been able to ascertain). However, whichever version you use: They are sadly slow when it comes to higher numbers, such as 9E615, as a lot of iterations have to be got through to normalise the numbers.

Strangely, although Qlib will compile it, it doesnt seem to work for numbers > 2^30 under Qlib! Dont yet know why (and Im not sure I care enough to find out!)

Finally, I wrote a single keyword toolkit in assembler. That works in about linear time (as the number it works with is already normalised). 104 bytes of code. Works across the range. If someone really needs this, and cant be bothered to write their own, they know where to get it!