- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
short program:
============================================================
program prime_number_table
!
implicit none
!
integer(kind=8), parameter :: MAX_PRIME = 4294967295 ! 2**32-1
integer(kind=8), parameter :: ROOT_MAX = int(sqrt(real(MAX_PRIME,8)),8)
integer(kind=8), parameter :: PI_MAX_PRIME = 150000
!
write(*,*) "MAX_PRIME: ", MAX_PRIME
write(*,*) "real(MAX_PRIME): ", real(MAX_PRIME,8)
write(*,*) "sqrt(real(MAX_PRIME)): ", sqrt(real(MAX_PRIME))
write(*,*) "int(sqrt(real(MAX_PRIME))): ", int(sqrt(real(MAX_PRIME)),8)
write(*,*) "ROOT_MAX: ", ROOT_MAX
read(*,*)
end program prime_number_table
=======================================================
Results:
MAX_PRIME: 4294967295
real(MAX_PRIME): 4294967295.00000
sqrt(real(MAX_PRIME)): 65536.00
int(sqrt(real(MAX_PRIME))): 65536
ROOT_MAX: 65535
========================================================
Is this a bug or a feature?
compiler version: Intel Visual Fortran Composer XE 2011 Integration for Microsoft Visual Studio* 2005, 12.0.3471.2005, Copyright (C) 2002-2011 Intel Corporation
Thank you very much in advance.
John D Bauer
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[bash]program prime_number_table implicit none !-- Kinds for specified real precisions. integer, parameter :: r4_kind = selected_real_kind(6,30) !-- 6 digits integer, parameter :: r8_kind = selected_real_kind(12,30) !-- 12 digits !-- Kinds for specified integer ranges. !-- Caveat: Not all compilers have a suitable i8_kind. integer, parameter :: i1_kind = selected_int_kind(2) !-- 99 max integer, parameter :: i2_kind = selected_int_kind(4) !-- 9,999 max integer, parameter :: i4_kind = selected_int_kind(9) !-- 999,999,999 max integer, parameter :: i8_kind = selected_int_kind(18) !-- 10**18-1 max integer(kind=i8_kind), parameter :: MAX_PRIME = 4294967295 ! 2**32-1 integer(kind=i8_kind), parameter :: ROOT_MAX = int(sqrt(real(MAX_PRIME,r8_kind)),i8_kind) integer(kind=i8_kind), parameter :: PI_MAX_PRIME = 150000 ! write(*,*) "MAX_PRIME: ", MAX_PRIME write(*,*) "real(MAX_PRIME): ", real(MAX_PRIME,r8_kind) write(*,*) "sqrt(real(MAX_PRIME)): ", sqrt(real(MAX_PRIME, r8_kind)) write(*,*) "int(sqrt(real(MAX_PRIME))): ", int(sqrt(real(MAX_PRIME, r8_kind)),i8_kind) write(*,*) "ROOT_MAX: ", ROOT_MAX read(*,*) end program prime_number_table [/bash]Output goes.
[bash] MAX_PRIME: 4294967295 real(MAX_PRIME): 4294967295.00000 sqrt(real(MAX_PRIME)): 65535.9999923706 int(sqrt(real(MAX_PRIME))): 65535 ROOT_MAX: 65535 [/bash]
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
real(MAX_PRIME,8)
as in the definition of ROOT_MAX
is not the same as:
real(MAX_PRIME)
in the WRITE that is different. The second one returns a single precision REAL value which does not have enough precision to hold MAX_PRIME.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
real(MAX_PRIME,8)
as in the definition of ROOT_MAX
is not the same as:
real(MAX_PRIME)
in the WRITE that is different. The second one returns a single precision REAL value which does not have enough precision to hold MAX_PRIME.
program prime_number_table
!
implicit none
!
integer(kind=8), parameter :: MAX_PRIME = 4294967295 ! 2**32-1
integer(kind=8), parameter :: ROOT_MAX = int(sqrt(real(MAX_PRIME,8)),8)
integer(kind=8), parameter :: PI_MAX_PRIME = 150000
!
write(*,*) "MAX_PRIME: ", 4294967295
write(*,*) "real(MAX_PRIME): ", real(4294967295,8) ! This is 64-bit floating point
write(*,*) "sqrt(real(MAX_PRIME)): ", sqrt(real(4294967295)) ! This is 32-bit floating point
write(*,*) "int(sqrt(real(MAX_PRIME))): ", int(sqrt(real(4294967295)),8) ! The square root return a 32-bit
! floating point number
write(*,*) "ROOT_MAX: ", 65536
read(*,*)
end program prime_number_table
============================================================
to be continued.....

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page