## Tricky Fortran if-statement

## Tricky Fortran if-statement

(OP)

Hi

I am trying to translate Fortran to C++, and I encountered a Fortran line I can't understand:

DOUBLE PRECISION FUNCTION ROUNDN (NUMBER,DEC)

DOUBLE PRECISION ARG,FACT,NUMBER,ROUND

ARG = DABS (NUMBER)

1 <calculations on label 1>

2 <calculations on label 2 >

My problem is the IF statement. Obviously it goes to label 1 or 2 depending on the outcome of DEC-1. But how does it work? What is the logic?

It is a rounding function. I don't want to paste in the very code since it is not mine.

For example, if NUMBER is 39.99 and DEC 1.0, it goes to 2.

Thankful for any help

Perry

I am trying to translate Fortran to C++, and I encountered a Fortran line I can't understand:

DOUBLE PRECISION FUNCTION ROUNDN (NUMBER,DEC)

DOUBLE PRECISION ARG,FACT,NUMBER,ROUND

ARG = DABS (NUMBER)

**IF(DEC-1.) 1,2,2**1 <calculations on label 1>

2 <calculations on label 2 >

My problem is the IF statement. Obviously it goes to label 1 or 2 depending on the outcome of DEC-1. But how does it work? What is the logic?

It is a rounding function. I don't want to paste in the very code since it is not mine.

For example, if NUMBER is 39.99 and DEC 1.0, it goes to 2.

Thankful for any help

Perry

## RE: Tricky Fortran if-statement

## CODE

## CODE

## RE: Tricky Fortran if-statement

Thank you for splendid answer! And no, it doesn't fall through since it does RETURN before next label.

I suspected this was REALLY old stuff... :-\

Thanks again!

Perry

## RE: Tricky Fortran if-statement

## CODE

## RE: Tricky Fortran if-statement

Seems there is an old math functions library I have here, where we have this old stuff...

## RE: Tricky Fortran if-statement

ROUND N = DSIGN (ROUND,NUMBER)

It should be (meaning it is interpreted as):

ROUNDN = DSIGN (ROUND,NUMBER)

No 'N' of type 'ROUND', as it seems.

Don't understand how things like this even compile... :-\

## RE: Tricky Fortran if-statement

## CODE