Float to Double

Everything else that doesn't fall into one of the other PB categories.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Float to Double

Post by Polo »

I want to convert a float to double without using user library.. I had seen an ASM code that do that, but I lost it and I can't refind it... Does someone have it ?
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Re: Float to Double

Post by WolfgangS »

Polo wrote:I want to convert a float to double without using user library.. I had seen an ASM code that do that, but I lost it and I can't refind it... Does someone have it ?
; *
; * Converts a Float to a Double
; *
Structure dblout
p1.l
p2.l
EndStructure

Procedure DoublePart1(flt.f)
Global _input.f:_input.f=flt
Global _dblout.dblout
!FLD dword[v__input]
!FST qword[v__dblout]
ProcedureReturn _dblout\p1
EndProcedure

Procedure DoublePart2(flt.f)
Global _input.f:_input.f=flt
Global _dblout.dblout
!FLD dword[v__input]
!FST qword[v__dblout]
ProcedureReturn _dblout\p2
EndProcedure

GiveDouble (DoublePart1(100),DoublePart2(100))

The value is max. 32 bit.

MFG
WolfgangS
WolfgangS' projects http://www.schliess.net
Quotation of the month:
<p3hicy>oder ich hol mir so eine geile aus asien
<p3hicy>die ständig poppen will
<p3hicy>'n brötchen pro tag reicht doch
<p3hicy>die essen eh' nich so viel
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Thanks, but what is this GiveDouble() function ?
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Polo wrote:Thanks, but what is this GiveDouble() function ?
I don't see GiveDouble as a standard PB funciton. But here is what I use:

Code: Select all

Structure Double
  Hi.l
  Lo.l
EndStructure

Procedure MakeDouble(LONG.f, ADDRESS.l)
  !FLD dword [ Esp ]
  !MOV dword Eax, [ Esp + 4 ]
  !FSTP qword [ Eax ]
EndProcedure

Procedure.l DrawImage(Left.f, Top.f, Width.f, Height.f)
  dLeft.Double
  dTop.Double
  dWidth.Double
  dHeight.Double
  MakeDouble(Left.f, @dLeft)
  MakeDouble(Top.f, @dTop)
  MakeDouble(Width.f, @dWidth)
  MakeDouble(Height.f, @dHeight)
  ProcedureReturn CallFunctionFast(FPDrawImage, dLeft\Hi, dLeft\Lo, dTop\Hi, dTop\Lo, dWidth\Hi, dWidth\Lo, dHeight\Hi, dHeight\Lo)
EndProcedure
- np
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Thanks, it works !
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post by WolfgangS »

Polo wrote:Thanks, but what is this GiveDouble() function ?
It shows you how to use the procedures.
WolfgangS' projects http://www.schliess.net
Quotation of the month:
<p3hicy>oder ich hol mir so eine geile aus asien
<p3hicy>die ständig poppen will
<p3hicy>'n brötchen pro tag reicht doch
<p3hicy>die essen eh' nich so viel
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..also

Post by NoahPhense »

Polo wrote:Thanks, it works !
also...

Here is a CatchDoubleReturn example:

Code: Select all

Procedure.f CatchDoubleReturn(*x.Double)
  !MOV  dword EAX,[ESP]
  !FST  qword [EAX]
  !MOV  dword EAX,[ESP]
  !FLD  qword [EAX]
EndProcedure
Used like:

Code: Select all

Procedure.f GetHTMLTextHeight(Width.f, HTMLText.s)
  dWidth.Double
  MakeDouble(Width.f, @dWidth)
  CallFunctionFast(FPGetHTMLTextHeight, dWidth\Hi, dWidth\Lo, HTMLText)
  ProcedureReturn CatchDoubleReturn(dummy.Double)
EndProcedure
lalala..

- np
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

it's really a shame you should have to go through all that trouble, just to use a double variable...
Let's hope new variable types are high on Fred's priority-/todo-list.. :)

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post by NoahPhense »

LarsG wrote:it's really a shame you should have to go through all that trouble, just to use a double variable...
Let's hope new variable types are high on Fred's priority-/todo-list.. :)
I think it is.. along with letting there be up to 40 parameters on a
procedure.. the parameters are being changed to meet some req's
of the iSED library ..

- np

* see, Fred just does a search now an then, for the key word Fred..
lol .. then he reads whats being said.. ;)

fred Fred FRED ... maybe I'll just make a library for them .. I'm sure
theres one out there already.. but I kinda like to know whats in em..
<eg> libs are easy to make now, with El's new app ..TailBite
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Re: ..

Post by techjunkie »

NoahPhense wrote:along with letting there be up to 40 parameters on a
procedure..
Ehhhh - didn't know that... What is the limit now?

Hmmm - in a Digital Flight Simulator I programmed a couple of years ago we had over 600 parameters in the main call - no use of PB there I'll guess... :lol:
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: ..

Post by NoahPhense »

techjunkie wrote:
NoahPhense wrote:along with letting there be up to 40 parameters on a
procedure..
Ehhhh - didn't know that... What is the limit now?

Hmmm - in a Digital Flight Simulator I programmed a couple of years ago we had over 600 parameters in the main call - no use of PB there I'll guess... :lol:
Yeah, it's being moved up. SedTech said it was currently at 20
parameters per procedure.

But, if I 'truly' had a need for 40 this very second. I could make it work.
I would just create the procedure to accept string delimited data, then
parse it just after it came into the procedure, assigning the data back
to their appropriate variable types.. 40, 60, 300, would work. But then
we would probably run into a line length issue anyhow, with the assembler.

I try not to worry about issues or hurdles if you will, until they are in my
face. And usually when that happens, I've always gotten a solution, or
created one.. :lol:

As for 600 parameters, that's just sick.. ;)

- np
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Re: ..

Post by techjunkie »

NoahPhense wrote:As for 600 parameters, that's just sick.. ;)
Well, it simulated a real aircraft and data for the engine was real engine data - impossible to simulate... As I remember, we had about 15000 variables in the system + the derivate of all variables... So - it was a big system, but it worked very well... in realtime... :D

About PB - if it is a limit of 20 parameters, that's real bad - I'm just lucky that I haven't broke the limit... *counting* Ehhhh - 18 parameters in that procedure... *LOL*
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

What advantage does 60 paramaters have over a single structure?
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Re: ..

Post by freedimension »

techjunkie wrote:
NoahPhense wrote:As for 600 parameters, that's just sick.. ;)
Well, it simulated a real aircraft and data for the engine was real engine data - impossible to simulate... As I remember, we had about 15000 variables in the system + the derivate of all variables... So - it was a big system, but it worked very well... in realtime... :D

About PB - if it is a limit of 20 parameters, that's real bad - I'm just lucky that I haven't broke the limit... *counting* Ehhhh - 18 parameters in that procedure... *LOL*
Well, you two could use Structures to pass Parameters to Procedures. This is recommended (at least by me) anyway, as it is faster and has more structure (no pun intended).
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: ..

Post by NoahPhense »

freedimension wrote:
techjunkie wrote:
NoahPhense wrote:As for 600 parameters, that's just sick.. ;)
Well, it simulated a real aircraft and data for the engine was real engine data - impossible to simulate... As I remember, we had about 15000 variables in the system + the derivate of all variables... So - it was a big system, but it worked very well... in realtime... :D

About PB - if it is a limit of 20 parameters, that's real bad - I'm just lucky that I haven't broke the limit... *counting* Ehhhh - 18 parameters in that procedure... *LOL*
Well, you two could use Structures to pass Parameters to Procedures. This is recommended (at least by me) anyway, as it is faster and has more structure (no pun intended).
True, care for a quick example? ;)

- np
Post Reply