Author |
Topic: Add 4 byte floats (Read 1164 times) |
|
Michael Hutton
Developer
member is offline


Gender: 
Posts: 248
|
 |
Add 4 byte floats
« Thread started on: Nov 17th, 2010, 01:43am » |
|
Just a wish list suggestion. I know the arguments against.
Michael
|
|
Logged
|
|
|
|
JGHarston
Junior Member
member is offline


Gender: 
Posts: 52
|
 |
Re: Add 4 byte floats
« Reply #1 on: Nov 25th, 2010, 9:56pm » |
|
on Nov 17th, 2010, 01:43am, Michael Hutton wrote:Just a wish list suggestion. I know the arguments against. |
|
Why?
Ie, what are the arguments for - how are you not able to achieve what you want with 5-byte floats? I would argue that 4-byte floats already exist, you just chose to ignore the fifth byte of a 5-byte float, in the same way that 16-bit integers already exist.
|
« Last Edit: Nov 25th, 2010, 9:59pm by JGHarston » |
Logged
|
|
|
|
softweir
New Member
member is offline


Posts: 12
|
 |
Re: Add 4 byte floats
« Reply #2 on: Nov 26th, 2010, 01:36am » |
|
Direct-X compatibility? It is possible that a Direct-X application might have a significant overhead inherent in converting 5-byte or 8-byte floats to 4-byte floats for passing to Direct-X.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Add 4 byte floats
« Reply #3 on: Nov 26th, 2010, 09:49am » |
|
on Nov 26th, 2010, 01:36am, softweir wrote:Direct-X compatibility? It is possible that a Direct-X application might have a significant overhead inherent in converting 5-byte or 8-byte floats to 4-byte floats for passing to Direct-X. |
|
That might be an argument for providing a built-in conversion function, but not for supporting 4-byte floats as a native data type.
I tried measuring the amount of time spent in calls to FN_f4 (the conversion function to 4-byte floats) in the 'tumbling teapot' Direct3D demonstration. It was so small the profiler didn't even register it! Even with the WAIT removed the conversion still took less than 10% of the total time.
Richard.
|
|
Logged
|
|
|
|
JGHarston
Junior Member
member is offline


Gender: 
Posts: 52
|
 |
Re: Add 4 byte floats
« Reply #4 on: Nov 27th, 2010, 8:32pm » |
|
on Nov 26th, 2010, 09:49am, Richard Russell wrote:That might be an argument for providing a built-in conversion function, but not for supporting 4-byte floats as a native data type. |
| Odd, when I wrote this 11 years ago (!) the documents I refered to stated the exponent was 8 bits, so using !(1+^real) would give you a 4-byte float, a construction I've occasionally used.
Experimentation and examining FN_f4() suggests
float4%=!(1+^float5):?(^float4%+3)=?(^float4%+3)-&40
works, but I've lost a bit of the exponent somewhere.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Add 4 byte floats
« Reply #5 on: Nov 27th, 2010, 10:29pm » |
|
on Nov 27th, 2010, 8:32pm, JGHarston wrote:Experimentation and examining FN_f4() suggests |
|
Today I added a section to the relevant Wiki article, listing some assembler code which can convert BBC BASIC (variant) numeric values into 4-byte floats very much faster that the standard FN_f4() routine - in fact more than ten times faster:
http://bb4w.wikispaces.com/Using+32-bit+floating+point+values
Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Add 4 byte floats
« Reply #6 on: Nov 28th, 2010, 11:26am » |
|
on Nov 27th, 2010, 8:32pm, JGHarston wrote:float4%=!(1+^float5):?(^float4%+3)=?(^float4%+3)-&40 works, but I've lost a bit of the exponent somewhere. |
|
It isn't that simple, because the sign bit is in a completely different place. The simplest BASIC code I've managed which gives identical results to FN_f4() is as follows:
Code: DEF FN_f4b(A)
LOCAL A%
A *= 1.0
A% = !^A AND &7FFFFFFF
IF (A% AND &1FF)<>&80 A% += &80
= SGN(A) AND &80000000 OR ?(^A+4) - 1 << 23 OR A% >>> 8 Of course, this only works in *FLOAT40 mode. The A *= 1.0 can be dispensed with if you know A isn't an integer.
n.b. If the mantissa is >= &7FFFFF80 the code will fail with a 'Number too big' error when it attempts to do the rounding, so it's not actually usable as it stands.
Richard.
|
|
Logged
|
|
|
|
|