Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Ada Programming/Attributes/'Remainder

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Description X'Remainder(Y,Z) is an Ada attribute where X is any floating-point type and Y,Z are any instances of that type. This attribute represents the fractional part of this result. Z should never be zero. The sign of Y may or may not be the same as the sign of the result. Example type Real is digits 15; Real'Remainder (7.5, 2.3); -- returns 0.6 Real'Remainder (42.97482350828000, 6.283185307179586); -- returns -1.00747364197711 -------------------------------------------------------------------------------- -- Mod function for real numbers -- -- x = The number whose remainder is desired -- y = The divisor -- -- We return x mod y with the same sign as y. -------------------------------------------------------------------------------- function "mod" (x, y : Real) return Real is result : Real := Real'Remainder (x, y); begin if y > 0.0 then if result < 0.0 then result := result + y; end if; else if result > 0.0 then result := result + y; end if; end if; return result; end "mod"; -------------------------------------------------------------------------------------------------- -- Rem function for real numbers -- -- x = The number whose remainder is desired -- y = The divisor -- -- We return x mod y with the same sign as x. -------------------------------------------------------------------------------------------------- function "rem" (x, y : Real) return Real is result : Real := Real'Remainder (x, y); begin if x > 0.0 then if result < 0.0 then result := result + abs y; end if; else if result > 0.0 then result := result - abs y; end if; end if; return result; end "rem"; See also Wikibook Ada Programming Ada Programming/Attributes Ada Programming/Attributes/'Rounding Ada Programming/Attributes/'Truncation Ada Programming/Attributes/'Unbiased_Rounding Ada Reference Manual 13 3 Operational and Representation Attributes K Language-Defined Attributes Remainder