User Tools

A PCRE internal error occured. This might be caused by a faulty plugin

====== Function ABS ====== ====Syntax==== * **abs** //number// → //absolute-value// ====Arguments and Values==== * //number// - a //[[CL:Glossary:number]]//. * //absolute-value// - a non-negative //[[CL:Glossary:real]]//. ====Description==== **abs** returns the absolute value of //number//. If //number// is a //[[CL:Glossary:real]]//, the result is of the same //[[CL:Glossary:type]]// as //number//. If //number// is a //[[CL:Glossary:complex]]//, the result is a positive //[[CL:Glossary:real]]// with the same magnitude as //number//. The result can be a //[[CL:Glossary:float]]// even if //number//'s components are //[[CL:Glossary:rationals]]// and an exact rational result would have been possible. Thus the result of ''(abs #c(3 4))'' can be either ''5'' or ''5.0'', depending on the implementation. ====Examples==== <blockquote> (abs 0) <r>0 </r> (abs 12/13) <r>12/13 </r> (abs -1.09) <r>1.09 </r> (abs #c(5.0 -5.0)) <r>7.071068 </r> (abs #c(5 5)) <r>7.071068 </r> (abs #c(3/5 4/5)) <r>1 ; or approximately 1.0 </r> ([[CL:Functions:eql]] (abs -0.0) -0.0) <r>//[[CL:Glossary:true]]//</r> </blockquote> ====Affected By==== None. ====Exceptional Situations==== None. ====See Also==== * {\secref\FloatSubstitutability} ====Notes==== If //number// is a //[[CL:Glossary:complex]]//, the result is equivalent to the following: <blockquote> (abs //number//) ≡ ([[CL:Functions:sqrt]] ([[CL:Functions:math-add|+]] ([[CL:Functions:expt]] ([[CL:Functions:realpart]] //number//) 2) ([[CL:Functions:expt]] ([[CL:Functions:imagpart]] //number//) 2))) </blockquote> An implementation should not use this formula directly for all //[[CL:Glossary:complexes]]// but should handle very large or very small components specially to avoid intermediate overflow or underflow. \issue{REAL-NUMBER-TYPE:X3J13-MAR-89} \issue{REAL-NUMBER-TYPE:X3J13-MAR-89} \issue{COMPLEX-RATIONAL-RESULT:EXTEND}