For Programmers: Free Programming Magazines  


Home > Archive > Fortran > August 2005 > selected integer kind









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author selected integer kind
Bart Vandewoestyne

2005-08-25, 3:57 am

I'm a bit ... i declared an integer kind as follows:

integer, parameter, public :: i8b = selected_int_kind(14)

wich should guarantee me that i can use values up to 1e14.

If i declare an integer of this kind

integer(kind=i8b) :: x_i8b

and then I ask for the largest integer using the HUGE intrinsic:

write(unit=*, fmt="(A, I0.0)") " Largest integer for i8b is: ", huge(i8b)

then I get:

Largest integer for i8b is: 2147483647

which is 2.147483647e9 and is definitely smaller than my
requested 1e14.


Am i misinterpreting the SELECTED_INT_KIND and HUGE intrinsics
here?

For your information:

My compiler:
Fortran Company/NAG F compiler Release 20031017

My architecture:
Intel(R) Pentium(R) 4 CPU 2.40GHz on a stable Debian GNU/Linux
system.

Regards,
Bart

--
"Share what you know. Learn what you don't."
James Van Buskirk

2005-08-25, 8:00 am

"Bart Vandewoestyne" <MyFirstName.MyLastName@telenet.be> wrote in message
news:1124958443.633665@seven.kulnet.kuleuven.ac.be...

> write(unit=*, fmt="(A, I0.0)") " Largest integer for i8b is: ",

huge(i8b)

Possible corrections:

write(unit=*, fmt="(A, I0.0)") " Largest integer for i8b is: ", huge(x_i8b)
write(unit=*, fmt="(A, I0.0)") " Largest integer for i8b is: ", huge(0_i8b)
write(unit=*, fmt="(A, I0.0)") " Largest integer for i8b is: ",
huge(int(0,i8b))

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


Phillip Helbig---remove CLOTHES to reply

2005-08-25, 8:00 am

In article <1124958443.633665@seven.kulnet.kuleuven.ac.be>, Bart
Vandewoestyne <MyFirstName.MyLastName@telenet.be> writes:

> I'm a bit ... i declared an integer kind as follows:
>
> integer, parameter, public :: i8b = selected_int_kind(14)
>
> wich should guarantee me that i can use values up to 1e14.


No, it guarantees you that you can use values up to the largest value
which can be expressed in the smallest data type which can be used to
express 14.

2147483647 is (2**31 - 1) which means that the smallest data type on
your processor with which 14 can be expressed is a 32-bit integer, and
the largest value of this data type is 2147483647. (This situation is
quite typical, by the way.)

Michel OLAGNON

2005-08-25, 8:00 am



Bart Vandewoestyne wrote:
> I'm a bit ... i declared an integer kind as follows:
>
> integer, parameter, public :: i8b = selected_int_kind(14)
>
> wich should guarantee me that i can use values up to 1e14.
>
> If i declare an integer of this kind
>
> integer(kind=i8b) :: x_i8b
>
> and then I ask for the largest integer using the HUGE intrinsic:
>
> write(unit=*, fmt="(A, I0.0)") " Largest integer for i8b is: ", huge(i8b)


Should be huge(x_i8b). The argument of huge should not be the kind value,
but a number of that kind.




>
> then I get:
>
> Largest integer for i8b is: 2147483647
>
> which is 2.147483647e9 and is definitely smaller than my
> requested 1e14.
>
>
> Am i misinterpreting the SELECTED_INT_KIND and HUGE intrinsics
> here?
>
> For your information:
>
> My compiler:
> Fortran Company/NAG F compiler Release 20031017
>
> My architecture:
> Intel(R) Pentium(R) 4 CPU 2.40GHz on a stable Debian GNU/Linux
> system.
>


Bart Vandewoestyne

2005-08-25, 8:00 am

On 2005-08-25, Michel OLAGNON <molagnon@ifremer-a-oter.fr> wrote:
>
>
> Should be huge(x_i8b). The argument of huge should not be the kind value,
> but a number of that kind.


Oh yes! Of course! Thanks!

Bart

--
"Share what you know. Learn what you don't."
Arjen Markus

2005-08-25, 8:00 am

selected_int_kind(r) uses its argument r as the exponent for the
_range_.
So the result should have been an integer that can take values at least
from
-10**r to 10**r.

It seems to me that the F compiler does not handle the error that seems
to have resulted (i8b should be negative and negative kind values are
not
allowed) ...

Regards,

Arjen

Bart Vandewoestyne

2005-08-25, 8:00 am

On 2005-08-25, Arjen Markus <arjen.markus@wldelft.nl> wrote:
> selected_int_kind(r) uses its argument r as the exponent for the
> _range_.
> So the result should have been an integer that can take values at least
> from
> -10**r to 10**r.
>
> It seems to me that the F compiler does not handle the error that seems
> to have resulted (i8b should be negative and negative kind values are
> not allowed) ...


This was also what I was thinking, but apparently I'm not the
only one not having spotted my typo (see other messages in this
thread ;-)

Regards,
Bart

--
"Share what you know. Learn what you don't."
Arjen Markus

2005-08-25, 8:00 am

Oh, wait, you mean that the F compiler does support a very big integer?
(So i8b gets a proper value and x_i8b can hold 14 digit integers but
due to
the typo you did not see it ... Okay!)

Regards,

Arjen

Bart Vandewoestyne

2005-08-25, 8:00 am

On 2005-08-25, Arjen Markus <arjen.markus@wldelft.nl> wrote:
> Oh, wait, you mean that the F compiler does support a very big integer?
> (So i8b gets a proper value and x_i8b can hold 14 digit integers but
> due to the typo you did not see it ... Okay!)


Yes. In fact, my Fortran Company/NAG F compiler Release 20031017
on my Intel(R) Pentium(R) 4 CPU 2.40GHz can even hold 18 digit
integers. Here's some output of a test-program of mine:

Radix for i8b is: 2
Digits in radix 2 for i8b is: 63
Largest integer for i8b is: 9223372036854775807
Equivalent decimal exponent range for i8b is: 18

That's some good news I didn't know of yet :-)

Regards,
Bart

--
"Share what you know. Learn what you don't."
John Mansell

2005-08-25, 8:00 am

See comments below

In message <1124958443.633665@seven.kulnet.kuleuven.ac.be>, Bart
Vandewoestyne <MyFirstName.MyLastName@telenet.be> writes
>I'm a bit ... i declared an integer kind as follows:
>
> integer, parameter, public :: i8b = selected_int_kind(14)

i8b is a *default* integer with compiler-dependent value (which doesn't
have to be vary large - I've seen 1,2,3,4 and 1,2,4,8...)

>
>wich should guarantee me that i can use values up to 1e14.
>
>If i declare an integer of this kind
>
> integer(kind=i8b) :: x_i8b
>
>and then I ask for the largest integer using the HUGE intrinsic:
>
> write(unit=*, fmt="(A, I0.0)") " Largest integer for i8b is: ", huge(i8b)


don't you mean huge(x_i8b)

>
>then I get:
>
> Largest integer for i8b is: 2147483647
>
>which is 2.147483647e9 and is definitely smaller than my
>requested 1e14.
>
>
>Am i misinterpreting the SELECTED_INT_KIND and HUGE intrinsics
>here?
>
>For your information:
>
>My compiler:
>Fortran Company/NAG F compiler Release 20031017
>
>My architecture:
>Intel(R) Pentium(R) 4 CPU 2.40GHz on a stable Debian GNU/Linux
>system.
>
>Regards,
>Bart
>


--
John Mansell john at wcompsys dot co dot uk

Jugoslav Dujic

2005-08-25, 8:00 am

John Mansell wrote:
| See comments below
|
| In message <1124958443.633665@seven.kulnet.kuleuven.ac.be>, Bart
| Vandewoestyne <MyFirstName.MyLastName@telenet.be> writes
|| I'm a bit ... i declared an integer kind as follows:
||
|| integer, parameter, public :: i8b = selected_int_kind(14)
|
| i8b is a *default* integer with compiler-dependent value (which doesn't
| have to be vary large - I've seen 1,2,3,4 and 1,2,4,8...)

INCLUDE " Usual_Richards_regrets_about_not_having_
a_separate_type_for_KINDs"
INCLUDE "Mine_too"

--
Jugoslav
___________
www.geocities.com/jdujic

Please reply to the newsgroup.
You can find my real e-mail on my home page above.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com