Ada Programming/Attributes/'Copy Sign

From Wikibooks, open books for an open world
Jump to: navigation, search

Ada Lovelace 1838.jpg

Contents


function S'Copy_Sign (Value, Sign : T)
  return T

[edit] Description

S'Copy_Sign(X, Y) is an Ada attribute where S is any floating-point type, and X and Y are any instance of that type. This attribute represents the floating point value with the magnitude of X and the sign of Y.

If the resulting value is outside the range of S, a Constraint_Error exception is raised.

[edit] Example

X : Float :=  1.5;
Y : Float := -1.0;
Z : Float :=  1.0;
 
pragma Assert (Float'Copy_Sign ( X, Y) = -1.5);   -- OK
pragma Assert (Float'Copy_Sign ( X, Z) =  1.5);   -- OK
pragma Assert (Float'Copy_Sign (-X, Z) =  1.5);   -- OK
pragma Assert (Float'Copy_Sign ( Y, Z) = -1.0);   -- Wrong

[edit] See also

[edit] Wikibook

[edit] Ada Reference Manual

Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
Sister projects
Print/export