[J3] branch based on ieee class ?

Vipul Parekh parekhvs at gmail.com
Thu Nov 7 11:42:31 EST 2019


Hello Dan,

See section 17.2 Derived types, constants, and operators defined in
the modules in 18-007r1.pdf, p3 on IEEE_ARITHMETIC module,
particularly lines 27 thru' 30 which state,

27 * The pure elemental operator == for two values of one of these
types to return true if the values are the
28   same and false otherwise.
29 * The pure elemental operator /= for two values of one of these
types to return true if the values differ and
30   false otherwise.

>From what I understand, you will have to construct your case using
either of the above-mentioned operators e.g.,

   use, intrinsic :: ieee_arithmetic, only : ieee_class,
ieee_negative_normal, operator(==)
   real :: x
   x = -1.0
   if ( ieee_class(x) == ieee_negative_normal ) then
      print *, "x is IEEE_NEGATIVE_NORMAL"
   else
      print *, "The IEEE class of x is not as expected!"
   end if
end

Upon execution, the program output is expected as:
 x is IEEE_NEGATIVE_NORMAL

Regards,
Vipul Parekh

On Thu, Nov 7, 2019 at 10:38 AM Dan Nagle via J3
<j3 at mailman.j3-fortran.org> wrote:
>
> Hi,
>
> How to?
>
> C1145 removes the select case option (my first choice), and
> Table 10.2 eliminates if-blocks by not listing ieee_class_type
> among the allowed operands for == and /= (or .eqv. and .neqv.).
>
> I'm writing a workshop on ieee 754 and I would like to write
> a diagnostic routine that can print "this is an X" where
> X is one of the ieee_class_type values.  So I want to branch
> to select the correct label per class.
>
> (With the select case, a range of values does not seem to make sense.
> But I want to case each one singly, so that's no matter to the task at hand.)
>
>
> --
>
> Cheers!
> Dan Nagle
>
>


More information about the J3 mailing list