Clicky

Fortran Wiki
modulo (Rev #3, changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #2 to #3: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

Description

modulo(a,p) computes the a modulo p.

Standard

Fortran 95 and later

Class

Elemental function

Syntax

result = modulo(a, p)

Arguments

  • a - Shall be a scalar of type integer or real
  • p - Shall be a scalar of the same type and kind as a

Return value

The type and kind of the result are those of the arguments.

  • (削除) (削除ここまで)(追記) If (追記ここまで)(削除)

    If a and p are of type integer: modulo(a,p) has the value r such that a=q*p+r, where q is an integer and r is between 0 (inclusive) and p (exclusive).

    (削除ここまで)
    (追記) a (追記ここまで)(削除) (削除ここまで)(追記) (追記ここまで)(追記) and (追記ここまで)(追記) p (追記ここまで)(追記) are of type (追記ここまで)(追記) integer (追記ここまで)(追記) : (追記ここまで)(追記) modulo(a,p) (追記ここまで)(追記) has the value (追記ここまで)(追記) r (追記ここまで)(追記) such that ‘a - floor (real(a) /real( p)) * p’ (追記ここまで)
  • (削除) (削除ここまで)(追記) If (追記ここまで)(削除)

    If a and p are of type real: modulo(a,p) has the value of a - floor (a / p) * p.

    (削除ここまで)
    (追記) a (追記ここまで)(削除) (削除ここまで)(追記) (追記ここまで)(追記) and (追記ここまで)(追記) p (追記ここまで)(追記) are of type (追記ここまで)(追記) real (追記ここまで)(追記) : (追記ここまで)(追記) modulo(a,p) (追記ここまで)(追記) has the value of (追記ここまで)(追記) a - floor (a / p) * p (追記ここまで)(追記) . (追記ここまで)

In all cases, if p is zero the result is processor-dependent.

Example

program test_modulo
 print *, modulo(17,3)
 print *, modulo(17.5,5.5)
 print *, modulo(-17,3)
 print *, modulo(-17.5,5.5)
 print *, modulo(17,-3)
 print *, modulo(17.5,-5.5)
end program

category: intrinsics

Revision from June 5, 2009 02:22:10 by ywzhong?
Forward in time (3 more) | Back in time (2 more) | See current | Hide changes | History | Rollback | View: Source | Linked from: Intrinsic procedures, mod

AltStyle によって変換されたページ (->オリジナル) /