flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Floating point calculation in fasm?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 10 Sep 2005, 15:29
Would it be possible to add floating point calculations?
something like this:
Code:
value = 5.0
pi = 3.141592654
newfloat = pi * value    


and / or

Code:
value equ 5.0
pi equ 3.141592654
newfloat equ pi*value    


or does this feature already exist, and I just haven't read the manual good enough yet.
Post 10 Sep 2005, 15:29
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 10 Sep 2005, 18:02
If you read the FPU section in the documentation [page 36 in my version], fldpi will load PI into the register stack for you so you don't have to declare it, you then use FPU operands (fadd,fsub,fmul,fdiv etc) on registers st0 - st7 to perform all normal operations.

HTH
Post 10 Sep 2005, 18:02
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 10 Sep 2005, 20:47
Yeh, I know that stuff already. But In many cases it would be easier to use equates, like when you need to change a value, you won't have to go though all your code and change every occurance of that value.
thanks anyways for your help.
Post 10 Sep 2005, 20:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 11 Sep 2005, 09:07
i usually precompute it myself ("calc.exe"), and define it as constant, with equate in comment so i can easily recompute (of course there are dependancy issues, but they are problems only in som extreme cases)
Post 11 Sep 2005, 09:07
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
polygon7



Joined: 14 Aug 2003
Posts: 62
Location: Poznan, Poland
polygon7 11 Sep 2005, 15:27

_________________
best regards
p7
Post 11 Sep 2005, 15:27
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 11 Sep 2005, 17:12
Vid:
Most of the time I do this too. In some case though It would be nice to define an equation and use a standard macro to calculate the value.
an example of the c snip that caused me to ask this question:
Code:
#define D3DX_PI 3.141592654
#define D3DX_1BYPI 0.318309886f
#define D3DXToRadian( degree ) ((degree) * (D3DX_PI / 180.0f))
#define D3DXToDegree( radian ) ((radian) * (180.0f / D3DX_PI))    

Id like to be able to do the same with FASM and a macro define

Polygon7:
Those macro's might work, but It would be better to have this as a standard feature for a future release of FASM. I don't think this would be much harder to implement than FASMs integer parser/calculator. I'll try the macro's and see if they will work for me. thanks.
Post 11 Sep 2005, 17:12
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 13 Sep 2005, 07:37
madmatt: you would end up having both whole-number constants (including labels) and floating constant, which wouldn't be distinguishable, so it will be just mess.
Post 13 Sep 2005, 07:37
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 13 Sep 2005, 16:42
naaa, these caculations would be all done internally and only the final result would be actual data:
mov eax, D3DXToRadian degree
OR
myvalue dd D3DXToRadian degree

anyways, If this would be to much trouble, I'll just find some work arounds. Just thought I would ask anyways
Post 13 Sep 2005, 16:42
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 13 Sep 2005, 18:18
ah, so you are talking about inline-macros, sorry, i didn't read carefully. I wanted to say that FASM doesn't allow FP calculations, so even 4.0/2.0 wouldn't work.
Post 13 Sep 2005, 18:18
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 13 Sep 2005, 19:46
Maybe in the next version of fasm Tomasz would look into adding this feature?
Post 13 Sep 2005, 19:46
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 14 Sep 2005, 19:14
i think not, it will cause mess with whole number constants. or you would allow somehting like "label jozo at 4.5"?
Post 14 Sep 2005, 19:14
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 14 Sep 2005, 23:52
I don't think it would be too much trouble to find the difference between a float and an integer. And where only an integer would be allowed and a fp number. Your example above would be flaged as an error in fasm, only floats would be allowed to be defined with equ, =, macro, data definitions, and direct loading of registers, (mov eax, 1.5). I think that covers about everything.
Post 14 Sep 2005, 23:52
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8363
Location: Kraków, Poland
Tomasz Grysztar 15 Sep 2005, 00:10
The operations performed by fasm are the integer operations, and thus:
Code:
beta = alpha * 2    

always means an integer operation, even if you defined alpha with a floating point value, since it is anyway stored as a binary representation, and then the integer operations are performed on this binary form. Thus this works the same as:
Code:
beta = alpha shl 1    

and in this case it's even more obvious that the operation is performed on binary.

To enable the floating point operations, they would have to be distinguished from the integer operations, and this means the floating point multiplication would have to get some other symbol than just the "*" like integer multiplication - in the same way like the floating point and integer arithmetics have separate instruction sets.
Post 15 Sep 2005, 00:10
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20489
Location: In your JS exploiting you and your system
revolution 15 Sep 2005, 00:58
Maybe this?
Code:
beta = alpha ** 2    
and simillarly we could have ++, --, //
Post 15 Sep 2005, 00:58
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8363
Location: Kraków, Poland
Tomasz Grysztar 15 Sep 2005, 01:33
But on what fp precision would it operate? You can define constants of various precisions, like:
Code:
a = dword 1.0
b = qword 1.0    

Would it needs separate operators for each precision, too? Is this feature worth such mess at all? That's why I suggested the macro solution - at least it's clear what's going on there.
Post 15 Sep 2005, 01:33
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20489
Location: In your JS exploiting you and your system
revolution 15 Sep 2005, 01:57
Quote:
But on what fp precision would it operate?
Okay, good point. The messyness factor might be an issue, but it is possble
Code:
beta = alpha ** 2 ;for SP
beta = alpha *** 2 ;for DP    
Post 15 Sep 2005, 01:57
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 15 Sep 2005, 08:53
revolution:
or how about beta == alpha * 2
everything behind the '==' would be float, or get converted to floats.

tomasz:
as far as size, use the best percision available, and scale down too what ever the data element needs, like dd beta, or dq beta, or mov eax, beta, etc.
Post 15 Sep 2005, 08:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20489
Location: In your JS exploiting you and your system
revolution 15 Sep 2005, 09:11
Quote:
how about beta == alpha * 2
The size becomes a problem like Tomasz Grysztar mentioned.
Quote:
use the best percision available, and scale down
The problem is how to distinguish between a float constant and an integer constant. eg. what is 0x12345678? Is it decimal 305419896, single precision 5.690457e-28 or double precision 1.588974781700064e-315?
Post 15 Sep 2005, 09:11
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 15 Sep 2005, 19:58
Hello Revolution,
Require floats to have a decimal point in them, or else it gets treated like an integer. All the values calclulated are going to be replaced withe the text equivalent, so the type of instruction and/or data define would determine the size, all internal fasmw calculations would be done using the highest precision possible (tword).
MadMatt
Post 15 Sep 2005, 19:58
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8363
Location: Kraków, Poland
Tomasz Grysztar 15 Sep 2005, 22:14
Consider this:
Code:
a = dword 1.0 ; so a = 3F800000h
b = qword 1.0 ; so b = 3FF0000000000000h
c = word 1    ; so c = 1
d = a+b*c    

Do you see what I mean? At least right now this sample doesn't cause any problems, since the * and + always mean the integer calculations in fasm, and when you know this it's simple to predict what the above definition will do.

And what do you mean by "are going to be replaced with the text equivalent"? In fasm it doesn't work this way; preprocessor works on text, assembler works on binary values.
Post 15 Sep 2005, 22:14
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.