Page 1 of 2

Float to Double

Posted: Sun Mar 14, 2004 10:01 am
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 ?

Re: Float to Double

Posted: Sun Mar 14, 2004 11:30 am
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

Posted: Sun Mar 14, 2004 11:51 am
by Polo
Thanks, but what is this GiveDouble() function ?

Posted: Sun Mar 14, 2004 2:45 pm
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

Posted: Sun Mar 14, 2004 4:50 pm
by Polo
Thanks, it works !

Posted: Sun Mar 14, 2004 5:33 pm
by WolfgangS
Polo wrote:Thanks, but what is this GiveDouble() function ?
It shows you how to use the procedures.

..also

Posted: Sun Mar 14, 2004 6:25 pm
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

Posted: Sun Mar 14, 2004 11:49 pm
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.. :)

..

Posted: Mon Mar 15, 2004 12:01 am
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

Re: ..

Posted: Mon Mar 15, 2004 1:23 am
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:

Re: ..

Posted: Mon Mar 15, 2004 2:14 am
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

Re: ..

Posted: Mon Mar 15, 2004 12:04 pm
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*

Posted: Mon Mar 15, 2004 12:25 pm
by GedB
What advantage does 60 paramaters have over a single structure?

Re: ..

Posted: Mon Mar 15, 2004 12:34 pm
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).

Re: ..

Posted: Mon Mar 15, 2004 4:33 pm
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