1
Result = (1.0D+0 + DBLE( Input rate)/ 1.0D + 5) ** (1.0D+0/1.2D+1) - 1.0D+0


A = idnint4 (result*1.0D+9);

These two lines of fortran code are confusing. I've converted many Fortran codes to C. But I fail to understand here why the author adds 1.0D+0 to the variable. It doesn't have an effect on the variable, no? Also idnint equivalent would be nint, which is not available in C library. Please remember I can use only C compiler, not even C++ compiler.

Can any Fortran expert guide me through this?

Update: I'm sorry to have confused you all regarding this. I do understand that 1.0D+0 is equal to 1. And adding that 1 definitely changes the value. What I meant was that what change does it make to write 1 as 1.0D+0? Trying to make that expression double? In that case, the variable 'input rate' if declared as double should be enough - no? I mean, if you add a double variable and a constant, the addition value should be double, no? Why try to make that whole expression double by using double in every part of the syntax?

Shiva S
  • 33
  • 6

4 Answers4

1

1.0D+0 is, well, one. Adding one to a number certainly changes the number.

I think "nint" just means "round".

tabstop
  • 1,751
  • 11
  • 10
1

As has been mentioned by everyone else, the D signifies double precision.

As for nint, you can mimic this in C by declaring the macro

#define nint(x) x - (int) x > 0.5 ? (int) x+1 : (int) x

Since (int) x intrinsically rounds down, we just subtract that from the initial value and see if the remainder (just the decimal place) is greater than a half. If it is, we use (int) x+1 otherwise we use (int) x.

Kyle Kanos
  • 3,257
  • 2
  • 23
  • 37
0

I see!

1.0D+.. means 10 to the power.

eg.

100 can be written as 1.0D+2 or 10.0D+1

Looking at the function, it is actually trying to multiply that number by 10 to power 9. Must be some required conversion.

Community
  • 1
  • 1
Digital_Reality
  • 4,488
  • 1
  • 29
  • 31
0

1.0D+0 is simply 1.0. D+0 is added to make it double precision i guess.

ignorant
  • 137
  • 1
  • 7