floating point numbers

Discuss any general programming issues here
Post Reply
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

floating point numbers

Post by lazi »

Hi!

There is Peek() and ReadFloat() which all requires double precision floating point numbers which takes 64 bit in memory.
Is there a way to handle simple precision 32 bit fp numbers in Hollywood?

Bye!
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: floating point numbers

Post by airsoftsoftwair »

No, in Hollywood all floating point values are 64-bit wide.
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: floating point numbers

Post by lazi »

May I ask it for a new feature?

I'd like to use dr2d drawings directly and that format uses such numbers. There is an old dr2d to hpgl converter on Aminet which I wrote (dr_hpgl), and like to port to hollywood. A little tweak on hpgl and we get complex 2d drawings in the form that Polygon() needs.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: floating point numbers

Post by airsoftsoftwair »

Hmm, I don't really see the advantage 32-bit floats would bring over 64-bit floats... please enlighten me :)
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: floating point numbers

Post by lazi »

The only advantage could be the ability to read files that stores single precision numbers.
But forget it, implemented as a function: :D

Code: Select all

;##########################################
;#                                        #
;#    CONVERTS FLOATING POINT NUMBERS     #
;#                                        #
;# doubleprecision=sp2dp(singleprecision) #
;#                                        #
;##########################################
Function sp2dp(sfp)
    Local sign, exponent, significand
    sign=(sfp>>31)&1
    exponent=((sfp>>23)&255)-127
    significand=sfp&$7fffff
    Local sigdec=1
    Local decoded=1
    For Local i=23 To 0 Step -1
        If BitTest(significand,i) Then decoded=decoded+sigdec
        sigdec=sigdec/2
    Next
    decoded=decoded*2^exponent
    If sign=1 Then decoded=decoded*-1
    Return(decoded)
EndFunction                   
Post Reply