I have a large expression (10k+ lines) which is implemented in fortran as a single instruction (just a huge formula with lots of line continuation symbols). The expression depends on x
. For some values of x
I would like to evaluate it in double precision, for other values of x I need to evaluate (also the whole expression) in quad precision, without duplicating the code of 10k+ lines.
I have tried to use an unlimited polymorphic variable for this declared as
class(*), allocatable :: x
and then after having allocated x with the correct precision I do
select type( var )
type is ( real(kind=16) )
! compute with
type is ( real(kind=8) )
write( *, * ) "real with double precision: ", var
end select
But that would still leave me duplicating the in the two cases of the select type. The reason is that I cannot have a case for generic floating point number, nor can I have mulitple checks in the SELECT TYPE
statement. Any suggestions?