Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sun, 24 Feb 2019 18:12:50 +0100
From: Markus Wichmann <>
Subject: Re: FE Exception triggered by comparison

On Mon, Feb 25, 2019 at 12:28:20AM +1100, Damian McGuckin wrote:
> What comparison of FP numbers trigger invalid operation exceptions?
> Does a comparison like
> 	if (x != x)
> 	{
> 		/* get to here if x == NaN *
> 	}
> which tests for a NaN cause an invalid operation if given an sNaN?
> Even reading the standard numerous times and I am not any wiser.
> Thanks - Damian

In cases like these, I like to read the documentation of an
implementation, under the assumption that it is conforming. One
implementation of IEE 754 general considered to be conforming is the x87
instruction set. And AMD's documentation of the same (AMD64 Architecture
Programmer's Manual, Volume 5, Order No. 26569) says about the FCOM
instruction, that it will generate an invalid-operation exception if any
source operand was a NaN. Same for FCOMI and FICOM.

Only difference for FUCOM and FUCOMI is that those only raise IE for an

Cross-checking with volume 4 shows that the SSE FP compare instructions
all raise IE in case of SNan source operand, and in case of "Undefined
operation". No idea what the latter is supposed to mean in context,
unless it means that QNaNs trigger it, too.

So yes, it appears at least in a PC, comparison with NaN raises IE.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.