Understanding Intrinsic 'Fraction' Function in Fortran

In summary, the 'fraction' function in Fortran is an intrinsic function that returns the fractional part of a real number. It is used by passing a real number as an argument and can also be used in mathematical expressions. The main difference between the 'fraction' function and other rounding functions is that it specifically returns the fractional part of a number. There are restrictions on the input, as it can only take in real numbers and only works with single precision numbers. However, it can be used with arrays in Fortran, returning an array of the same size with the fractional part of each element.
  • #1
PaulDirac
34
4
I have tried to use the intrinsic' fraction' function in Fortran but have failed to understand how it works. I thought that it would return the fractional part of a real number, but when I ran a few numbers through it, I got something that was a far cry from what I expected. For example, I tried fraction(10.0) and got 0.625. Can you tell me what's wrong?
 
Technology news on Phys.org

1. What is the intrinsic 'fraction' function in Fortran?

The 'fraction' function in Fortran is an intrinsic function that returns the fractional part of a real number. It is often used in mathematical calculations and can be helpful in rounding or truncating numbers.

2. How is the 'fraction' function used in Fortran?

The 'fraction' function is used by simply passing a real number as an argument. For example, 'fraction(3.14)' would return the value 0.14. It can also be used in mathematical expressions, such as 'x = fraction(5.5) + 1'.

3. What is the difference between the 'fraction' function and other rounding functions in Fortran?

The 'fraction' function specifically returns the fractional part of a number, while other rounding functions such as 'floor' and 'ceiling' return the closest integer value. For example, 'fraction(5.5)' would return 0.5, while 'floor(5.5)' would return 5.

4. Are there any restrictions on the input for the 'fraction' function?

The 'fraction' function can only take in real numbers as input. If a non-numeric value is passed, it will result in an error. Additionally, the function only works with single precision real numbers, so double precision numbers must be converted before being used with the function.

5. Can the 'fraction' function be used with arrays in Fortran?

Yes, the 'fraction' function can be used with arrays in Fortran. It will return an array of the same size, with the fractional part of each element in the original array. It can also be used with array expressions, such as 'x = fraction(arr1 + arr2)'.

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
13
Views
1K
  • High Energy, Nuclear, Particle Physics
Replies
1
Views
552
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • Programming and Computer Science
Replies
11
Views
9K
  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
5
Views
2K
Back
Top