News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

.IF floating point comparison

Started by aw27, July 22, 2017, 04:23:17 AM

Previous topic - Next topic

aw27

May be you can extend the already vast list of supported comparisons (when you have some time).

   .if real4 ptr myReal4>1.0 ; Works
   .endif
   
   .if real8 ptr myReal8>1.0 ; Does not work
   .endif
   
   .if real10 ptr myReal10>1.0 ; Does not work
   .endif

jj2007

Very tricky business - but not impossible, see Fcmp ::)

The issue is that you need to define a precision to decide whether two real numbers are "equal". Much bigger or much smaller is easy, but "almost" or "practically equal" is an important case in practice.

We had a thread on this eight years ago.

aw27

Quote from: jj2007 on July 22, 2017, 05:11:24 AM
Very tricky business - but not impossible, see Fcmp ::)

The issue is that you need to define a precision to decide whether two real numbers are "equal". Much bigger or much smaller is easy, but "almost" or "practically equal" is an important case in practice.

We had a thread on this eight years ago.

We establish an epsilon for the tolerance interval and check both sides.
Easy. UASM does not need to deal with that, it is a job for the ASM programmer.
DirectXMath has lots of functions with the NearEqual sufix, like XMVector3NearEqual, all work on that basis.

BugCatcher

Have a look at Raymond Filiatreaults site on floating point, chapter 7 -comparisons.
ray.masmcode.com

johnsa

Did you try using :



.if(real8 ptr myReal8 > FP8(1.0))
.endif



I haven't tested this, but worth checking and something we can then update soon.

johnsa

Had a quick look,

.if real4 ptr myReal4 < 1.0
.endif


will assemble, but it's not valid. It's generating a GPR cmp :

cmp real4 ptr myReal4, 0x......

which isn't going to be helpful.

So at present the supported modes are:

reg OP reg
reg OP float_immediate
reg OP [reg]     
reg OP [expr]           
reg OP variable

[reg] OP reg
[expr] OP reg
variable OP reg
These could be implemented relatively easily, by inverting the condition internally and swapping the comparison around.

[reg] OP [reg]
[reg] OP [expr]
[expr] OP [reg]
[reg] OP imm
variable OP imm
All these types would require some form of intermediate logic to set things up for the comparison, given it's hidden by the HLL it might be better to move the stuff around yourself as programmer to setup for a supported comparison mode above... I think .. :)