### Author Topic: .IF floating point comparison  (Read 1190 times)

#### AW

• Member
• Posts: 1725
• Let's Make ASM Great Again!
##### .IF floating point comparison
« on: July 22, 2017, 04:23:17 AM »
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

• Member
• Posts: 9092
• Assembler is fun ;-)
##### Re: .IF floating point comparison
« Reply #1 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.

#### AW

• Member
• Posts: 1725
• Let's Make ASM Great Again!
##### Re: .IF floating point comparison
« Reply #2 on: July 22, 2017, 06:08:10 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 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

• Regular Member
• Posts: 47
##### Re: .IF floating point comparison
« Reply #3 on: July 22, 2017, 06:33:36 AM »
Have a look at Raymond Filiatreaults site on floating point, chapter 7 -comparisons.
ray.masmcode.com

#### johnsa

• Member
• Posts: 730
##### Re: .IF floating point comparison
« Reply #4 on: July 26, 2017, 10:55:12 PM »
Did you try using :

Code: [Select]
`.if(real8 ptr myReal8 > FP8(1.0)).endif`
I haven't tested this, but worth checking and something we can then update soon.

#### johnsa

• Member
• Posts: 730
##### Re: .IF floating point comparison
« Reply #5 on: July 27, 2017, 12:08:45 AM »

.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 .. :)