Silverfrost Forums

Welcome to our forums

Wrong behaviour of ISHFT

12 Apr 2018 6:17 #21812

Hi, I found today that ISHFTing bits to the right does not give the right answer when the first argument is a PARAMETER, as per the following program:

program test_ishft implicit none integer, parameter :: n_par=20 integer :: n=20 integer :: n_double,n_half n_double=ishft(n,1) n_half=ishft(n,-1) print *,n_double,n_half ! correct: prints 40 and 10 n_double=ishft(n_par,1) n_half=ishft(n_par,-1) print *,n_double,n_half ! error: prints 40 and 0 (!!) end program test_ishft

compilation gives no errors:

$ ftn95 test_ishift.f95 [FTN95/Win32 Ver. 8.10.0 Copyright (c) Silverfrost Ltd 1993-2017] Licensed to: Rudnei Dias da Cunha Organisation: UFRGS

NO ERRORS  [<TEST_ISHFT> FTN95 v8.10.0]

but the results given are:

       40          10
       40           0

Also, this is the system I am working on: $ ftn95 /v

Silverfrost FTN95/Win32 Copyright (C) 1993-2017 Silverfrost Ltd
----------------------------------------------------------------

    Version:          8.10.0
    Built:            Sat Feb 11 12:23:39 2017

    Operating System: Windows NT    CPU:              Intel(R) Core(TM) i5-6400T CPU @ 2.20GHz Model 14 Step 3
    CPU Features:     MMX, SSE, SSE2, x86-64

Thanks for looking into it! Cheers Rudnei

12 Apr 2018 6:40 #21813

This does look like a bug.
Version: 8.30 reproduces this incorrect result.

Ken

12 Apr 2018 7:15 #21815

I have made a note that this needs investigating.

12 Apr 2018 7:20 #21817

I have just found out that

n_double=ishft(20,1)
n_half=ishft(20,-1)
print *,n_double,n_half ! error: prints 40 and 0 (!!)

also fails...

13 Apr 2018 8:15 #21821

This has now been fixed for the next release of FTN95.

(Internally the two cases are the equivalent, both being evaluated at compile time.)

13 Apr 2018 1:26 #21826

Dear Paul, Many thanks. Cheers Rudnei

Please login to reply.