soccer jersey forums.silverfrost.com :: View topic - FTN95 does not process ASSOCIATE construct correctly
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FTN95 does not process ASSOCIATE construct correctly

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
mecej4



Joined: 31 Oct 2006
Posts: 1896

PostPosted: Sun Jan 07, 2024 6:49 pm    Post subject: FTN95 does not process ASSOCIATE construct correctly Reply with quote

Paul, I do not have much experience using ASSOCIATE, and my expectations regarding what the following test program should do may be unjustified.

Code:
program cubesift

  implicit none
  integer, parameter :: IMAX = 4
  integer            :: year, i, bits
  integer, parameter :: cubes(IMAX) = [ (i*i*i, i = 1, IMAX) ]

  bits = 1
  associate (bmask => btest(bits,[(i-1, i = 1, IMAX)]))
     year = sum(cubes, mask = bmask)
     print '(i5, 4x,4L2)',year,bmask
  end associate

end program


FTN95 gives the output

Code:
  100     T


whereas other compilers give

Code:
    1     T F F F


The array "cubes" contains [1^3, 2^3, 3^3, 4^3]. The mask array "bmask" has only the first element set to .T., so "sum" should be applied to just [1^3], yielding 1.

The FTN95-compiled code appears to make "bmask" a scalar 'T', which then gets replicated three times in the expression sum(cubes, mask = bmask). As a result, "year" is evaluated as sum([1^3, 2^3, 3^3, 4^3]), i.e., 100.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8011
Location: Salford, UK

PostPosted: Mon Jan 08, 2024 10:06 am    Post subject: Reply with quote

mecej4

Thank you for the bug report. I have logged this for investigation.
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8011
Location: Salford, UK

PostPosted: Thu Feb 01, 2024 12:22 pm    Post subject: Reply with quote

This failure has now been fixed for the next release of FTN95.
Back to top
View user's profile Send private message AIM Address
mecej4



Joined: 31 Oct 2006
Posts: 1896

PostPosted: Thu Feb 01, 2024 1:57 pm    Post subject: Reply with quote

Thanks.

Here is the program from which the bug reproducer of this thread was created, if you wish to verify that the fix works on it, too.

Code:

! Given a range of years between 1 and 13^3-1, list years that may be
! expressed as the sum of cubes of integers with no repetitions allowed/
! Pipe the output of the program through the system SORT utility
program cubem

  implicit none
  integer, parameter :: YLOW = 2020, YHIGH = 2030
  integer, parameter :: IMAX = 12          ! smallest possible I s.t. (I+1)^3 > YHIGH
  integer            :: year, i, nk, bits
  integer, parameter :: cubes(IMAX) = [ (i*i*i, i = 1, IMAX) ]

  nk = 0
  do bits = 1, ishft (1, IMAX)-1
     associate (bmask => btest(bits,[(i-1, i = 1, IMAX)]))
        year = sum(cubes, mask = bmask)
        if (year < YLOW .or. year > YHIGH) cycle
        nk = nk+1
        print '(i6,4x,10i3)',year,pack([(i, i = 1, IMAX)], mask=bmask)
     end associate
  end do
  print '(/,A,i4,A)','Found ',nk,' years that are sums of cubes'

end program


The expected output:

Code:
  2024      2  3  4  5  6  7  8  9
  2025      1  2  3  4  5  6  7  8  9
  2023      2  5  6  7 11
  2024      1  2  5  6  7 11

Found    4 years that are sums of cubes
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8011
Location: Salford, UK

PostPosted: Thu Feb 01, 2024 2:37 pm    Post subject: Reply with quote

mecej4

Thanks. That also works.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group