Silverfrost Forums

Welcome to our forums

Max value of EXP(x) with x defined with KIND = 3

30 Jun 2014 3:17 #14302

If I define a real constant x, with KIND =1 (i.e. REAL*4), then the maximum value of EXP(x) which does not cause a floating point exception is approximately x = 88. I can understand this as e**88 is just less than HUGE(x) for KIND =1.

Defining x with KIND = 2 (i.e. REAL*8 ), then the maximum value of EXP(x) increases to x = 709, with EXP(x) now being just less than HUGE(x) for KIND = 2.

Selecting KIND =3, I was anticipating an increase in x, beyond 709 as HUGE(x) for KIND = 3 is much larger. But this does not appear to be the case, and I’m curious as to why this is so?

Defining X as REAL(SELECTED_REAL_KIND(18,4931)) X , does not appear to help.

Cheers

Ken

30 Jun 2014 6:43 #14303

Can you run the following code.

Program real_kinds

! Consider reals of the three kinds
real (1) :: x
real (2) :: y
real (3) :: z

! Print their ranges and precisions
print *,' kind 1 range ', range(x), ' precision ', precision(x), ' Huge ', huge(x)
print *,' kind 2 range ', range(y), ' precision ', precision(y), ' Huge ', huge(y)
print *,' kind 3 range ', range(z), ' precision ', precision(z), ' Huge ', huge(z)

print *,' Approx kind 1 max ', 10.0_1**range(x), ' Approx max x in exp(x) ', log(10.0_1**range(x))
print *,' Approx kind 2 max ', 10.0_2**range(y), ' Approx max y in exp(y) ', log(10.0_2**range(y))
print *,' Approx kind 3 max ', 10.0_3**range(z), ' Approx max z in exp(z) ', log(10.0_3**range(z))

End Program real_kinds

I get:

kind 1 range 37 precision 6 Huge 3.402823E+38 kind 2 range 307 precision 15 Huge 1.797693134862E+0308 kind 3 range 4931 precision 18 Huge 1.18973149535723177E+4932 Approx kind 1 max 1.000000E+37 Approx max x in exp(x) 85.1956 Approx kind 2 max 1.000000000000E+0307 Approx max y in exp(y) 706.893623549 Approx kind 3 max 1.00000000000000001E+4931 Approx max z in exp(z) 11354.047093553639

So you should be able to calculate exp(z) with z approx. 11354 with kind 3.

Since you can't calculate exp(11354.0_3), this could be a [u:9d7f965a77]bug[/u:9d7f965a77] in the compiler.

As a workaround you can use exp(1.0_3)**11354.0_3, which seems to work.

Hopefully Paul can put this on his investigate list 😃

30 Jun 2014 7:43 #14305

I have fixed this bug for the next release.

30 Jun 2014 9:03 #14306

Thanks guys. I was pulling my hair out over this on Sunday. Cheers Ken

Please login to reply.