RealCopySign

A real with the magnitude of one operand and the sign of another.

Declaration

Syntax

RealCopySign(expr target, expr source, ttype type, expr? value)

Arguments

Argument

Description

target

the value whose magnitude is taken.

source

the value whose sign is taken.

type

the type of the expression.

value

the compile time value of the expression, when the frontend could fold it; nil otherwise.

Return values

The value of the expression.

Description

This is sign(a, b). It is a node of its own rather than an intrinsic call because it maps to a single machine instruction, and because it is generated by the sign_from_value optimisation pass.

The sign is copied from the bit, so a negative zero source gives a negative result.

Examples

(RealCopySign
  :target (Var
    :v (SymbolRef 1 "x")
  )
  :source (RealConstant
    :r -1.0
    :type (Real
      :kind 8
    )
  )
  :type (Real
    :kind 8
  )
  :value nil
)

It comes from this complete ASR text document:

(TranslationUnit
  :symtab (SymbolTable
    :id 0
    :symbols {
      "main" (Program
        :symtab (SymbolTable
          :id 1
          :symbols {
            "b" (Variable
              :parent_symtab 1
              :name "b"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Logical
                :kind 4
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "x" (Variable
              :parent_symtab 1
              :name "x"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Real
                :kind 8
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
            "y" (Variable
              :parent_symtab 1
              :name "y"
              :dependencies []
              :intent :Local
              :symbolic_value nil
              :value nil
              :storage :Default
              :type (Real
                :kind 8
              )
              :type_declaration nil
              :abi :Source
              :access :Public
              :presence :Required
              :value_attr false
              :target_attr false
              :contiguous_attr false
              :bindc_name nil
              :is_volatile false
              :is_protected false
              :pass_attr :NotMethod
              :self_argument nil
              :codims []
            )
          }
        )
        :name "main"
        :dependencies []
        :body [
          (Assignment
            :target (Var
              :v (SymbolRef 1 "x")
            )
            :value (RealConstant
              :r 2.5
              :type (Real
                :kind 8
              )
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "y")
            )
            :value (RealBinOp
              :left (Var
                :v (SymbolRef 1 "x")
              )
              :op :Div
              :right (RealConstant
                :r 2.0
                :type (Real
                  :kind 8
                )
              )
              :type (Real
                :kind 8
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "y")
            )
            :value (RealUnaryMinus
              :arg (Var
                :v (SymbolRef 1 "x")
              )
              :type (Real
                :kind 8
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "y")
            )
            :value (RealSqrt
              :arg (Var
                :v (SymbolRef 1 "x")
              )
              :type (Real
                :kind 8
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "y")
            )
            :value (RealCopySign
              :target (Var
                :v (SymbolRef 1 "x")
              )
              :source (RealConstant
                :r -1.0
                :type (Real
                  :kind 8
                )
              )
              :type (Real
                :kind 8
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
          (Assignment
            :target (Var
              :v (SymbolRef 1 "b")
            )
            :value (RealCompare
              :left (Var
                :v (SymbolRef 1 "x")
              )
              :op :GtE
              :right (Var
                :v (SymbolRef 1 "y")
              )
              :type (Logical
                :kind 4
              )
              :value nil
            )
            :overloaded nil
            :realloc_lhs false
            :move_allocation false
          )
        ]
      )
    }
  )
  :items []
)

See Also

RealUnaryMinus, RealSqrt, IntrinsicElementalFunction