BBC BASIC for Windows
« Add 4 byte floats »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:52pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Add 4 byte floats  (Read 1163 times)
Michael Hutton
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 248
xx Add 4 byte floats
« Thread started on: Nov 17th, 2010, 01:43am »

Just a wish list suggestion. I know the arguments against.

Michael
User IP Logged

JGHarston
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 52
xx 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 » User IP Logged

softweir
New Member
Image


member is offline

Avatar




PM


Posts: 12
xx 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.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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.
User IP Logged

JGHarston
Junior Member
ImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 52
xx 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.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls