Author |
Topic: Determining the FLOAT mode in use. (Read 500 times) |
|
sveinioslo
Developer
member is offline


Posts: 64
|
 |
Determining the FLOAT mode in use.
« Thread started on: Mar 24th, 2015, 3:39pm » |
|
I need for a proc to know the FLOAT mode in use, and what version of BBC, 5 or 6. Can't remember to ever have read how to, searching YAHOO gave much interesting info, but no answer.
So i wrote this program to determine the version and float mode. There is perhaps a better and safer way ? Svein
Code: *FLOAT 40
PRINT "floatmode is ";FNfloat
*FLOAT 64
PRINT "floatmode is ";FNfloat
ON ERROR : PRINT "BBCv_5" : END
*FLOAT 80
PRINT "floatmode is ";FNfloat
PRINT "BBCv_6"
END
DEF FNfloat
LOCAL a,b,A%,B%,I%,J%,eq%,bytes%
a=1 : a*=1.0# : b=1 : b*=1.0#
A%=^a : B%=^b
bytes%=5
REPEAT
eq%=0
FOR J%=1 TO 10
a=RND(1)
FOR I%=0 TO bytes%-1
B%?I%=A%?I%
NEXT I%
IF a=b THEN eq%+=1
NEXT J%
IF eq%=10 THEN
IF bytes%=5 THEN =40
IF bytes%=8 THEN =64
=80
ENDIF
IF bytes%=10 THEN =0
IF bytes%=8 THEN bytes%=10
IF bytes%=5 THEN bytes%=8
UNTIL 0
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: Determining the FLOAT mode in use.
« Reply #1 on: Mar 24th, 2015, 5:05pm » |
|
on Mar 24th, 2015, 3:39pm, sveinioslo wrote:There is perhaps a better and safer way ? |
|
Your code seems to report the *FLOAT mode incorrectly in v6.00a. Here I get:
Code:floatmode is 80
floatmode is 80
floatmode is 80
BBCv_6 If you want to find the true *FLOAT mode you can do so directly by testing the relevant flag bits at ?419, which is documented on the Wiki:
Code: CASE ?419 AND 3 OF
WHEN 0: PRINT "*FLOAT 40"
WHEN 1: PRINT "*FLOAT 64"
WHEN 2: PRINT "*FLOAT 80"
ENDCASE But if what you want to know is the precision of a (suffixless) 'variant' numeric variable the most direct method is to use CALL:
Code: DEF FNprecision
LOCAL M%,P%
DIM P% LOCAL 10
[OPT 0
.M%
movzx eax,byte [ebp+6]
mov edi,[ebp+2]
mov [edi],eax
ret
]
CALL M%, P%, a
= P% * 8 That also tells you the version, because if the returned value is 40 or 64 it must be BB4W v5 and if the returned value is 80 it must be BB4W v6.
Richard.
|
« Last Edit: Mar 24th, 2015, 5:06pm by rtr2 » |
Logged
|
|
|
|
sveinioslo
Developer
member is offline


Posts: 64
|
 |
Re: Determining the FLOAT mode in use.
« Reply #2 on: Mar 24th, 2015, 7:21pm » |
|
Great, thank you!
The precision of a (suffixless) 'variant' numeric variable was exactly what i wanted. I do not know, if knowing the version will be required, but just i case...... Forgot about the 'Interpreter internal variables' page, just found some other needed info. 
Svein
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: Determining the FLOAT mode in use.
« Reply #3 on: Mar 25th, 2015, 06:47am » |
|
on Mar 24th, 2015, 5:05pm, g4bau wrote:But if what you want to know is the precision of a (suffixless) 'variant' numeric variable |
|
Here's an even more straightforward method, which works by finding out how much memory the variable occupies:
Code: DEF FNprecision
LOCAL s{}
DIM s{a}
= DIM(s{}) * 8 Richard.
|
|
Logged
|
|
|
|
sveinioslo
Developer
member is offline


Posts: 64
|
 |
Re: Determining the FLOAT mode in use.
« Reply #4 on: Mar 25th, 2015, 3:47pm » |
|
Nice 
Svein
|
|
Logged
|
|
|
|
|