1511dd36bSDavid Schultz.\" Copyright (c) 2007-2008 David Schultz <das@FreeBSD.org> 2aaf70b23SDavid Schultz.\" All rights reserved. 3aaf70b23SDavid Schultz.\" 4aaf70b23SDavid Schultz.\" Redistribution and use in source and binary forms, with or without 5aaf70b23SDavid Schultz.\" modification, are permitted provided that the following conditions 6aaf70b23SDavid Schultz.\" are met: 7aaf70b23SDavid Schultz.\" 1. Redistributions of source code must retain the above copyright 8aaf70b23SDavid Schultz.\" notice, this list of conditions and the following disclaimer. 9aaf70b23SDavid Schultz.\" 2. Redistributions in binary form must reproduce the above copyright 10aaf70b23SDavid Schultz.\" notice, this list of conditions and the following disclaimer in the 11aaf70b23SDavid Schultz.\" documentation and/or other materials provided with the distribution. 12aaf70b23SDavid Schultz.\" 13aaf70b23SDavid Schultz.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14aaf70b23SDavid Schultz.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15aaf70b23SDavid Schultz.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16aaf70b23SDavid Schultz.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17aaf70b23SDavid Schultz.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18aaf70b23SDavid Schultz.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19aaf70b23SDavid Schultz.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20aaf70b23SDavid Schultz.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21aaf70b23SDavid Schultz.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22aaf70b23SDavid Schultz.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23aaf70b23SDavid Schultz.\" SUCH DAMAGE. 24aaf70b23SDavid Schultz.\" 25*6d080f86SMateusz Piotrowski.Dd November 4, 2018 26aaf70b23SDavid Schultz.Dt CSQRT 3 27aaf70b23SDavid Schultz.Os 28aaf70b23SDavid Schultz.Sh NAME 29aaf70b23SDavid Schultz.Nm csqrt , 30511dd36bSDavid Schultz.Nm csqrtf , 31511dd36bSDavid Schultz.Nm csqrtl 32aaf70b23SDavid Schultz.Nd complex square root functions 33aaf70b23SDavid Schultz.Sh LIBRARY 34aaf70b23SDavid Schultz.Lb libm 35aaf70b23SDavid Schultz.Sh SYNOPSIS 36aaf70b23SDavid Schultz.In complex.h 37aaf70b23SDavid Schultz.Ft double complex 38aaf70b23SDavid Schultz.Fn csqrt "double complex z" 39aaf70b23SDavid Schultz.Ft float complex 40aaf70b23SDavid Schultz.Fn csqrtf "float complex z" 41511dd36bSDavid Schultz.Ft long double complex 42511dd36bSDavid Schultz.Fn csqrtl "long double complex z" 43aaf70b23SDavid Schultz.Sh DESCRIPTION 44aaf70b23SDavid SchultzThe 45511dd36bSDavid Schultz.Fn csqrt , 46511dd36bSDavid Schultz.Fn csqrtf , 47aaf70b23SDavid Schultzand 48511dd36bSDavid Schultz.Fn csqrtl 49aaf70b23SDavid Schultzfunctions compute the square root of 50aaf70b23SDavid Schultz.Fa z 51aaf70b23SDavid Schultzin the complex plane, with a branch cut along the negative real axis. 52aaf70b23SDavid SchultzIn other words, 53511dd36bSDavid Schultz.Fn csqrt , 54511dd36bSDavid Schultz.Fn csqrtf , 55aaf70b23SDavid Schultzand 56511dd36bSDavid Schultz.Fn csqrtl 57aaf70b23SDavid Schultzalways return the square root whose real part is non-negative. 58aaf70b23SDavid Schultz.Sh RETURN VALUES 59aaf70b23SDavid SchultzThese functions return the requested square root. 60aaf70b23SDavid SchultzThe square root of 0 is 61aaf70b23SDavid Schultz.Li +0 \*(Pm 0 , 62aaf70b23SDavid Schultzwhere the imaginary parts of the input and respective result have 63aaf70b23SDavid Schultzthe same sign. 64aaf70b23SDavid SchultzFor infinities and \*(Nas, the following rules apply, with the 65aaf70b23SDavid Schultzearlier rules having precedence: 66aaf70b23SDavid Schultz.Bl -column -offset indent "-\*(If + \*(Na*I" "\*(If \*(Pm \*(If*I " "(for all k)" 67748611c9SJoel Dahl.Em "Input" Ta Em "Result" Ta \& 68aaf70b23SDavid Schultzk + \*(If*I \*(If + \*(If*I (for all k) 69748611c9SJoel Dahl-\*(If + \*(Na*I \*(Na \*(Pm \*(If*I \& 70748611c9SJoel Dahl\*(If + \*(Na*I \*(If + \*(Na*I \& 71748611c9SJoel Dahlk + \*(Na*I \*(Na + \*(Na*I \& 72748611c9SJoel Dahl\*(Na + k*I \*(Na + \*(Na*I \& 73748611c9SJoel Dahl-\*(If + k*I +0 + \*(If*I \& 74748611c9SJoel Dahl\*(If + k*I \*(If + 0*I \& 75aaf70b23SDavid Schultz.El 76aaf70b23SDavid Schultz.Pp 77aaf70b23SDavid SchultzFor numbers with negative imaginary parts, the above special cases 78aaf70b23SDavid Schultzapply given the identity: 79*6d080f86SMateusz Piotrowski.Dl csqrt(conj(z)) = conj(csqrt(z)) 80aaf70b23SDavid SchultzNote that the sign of \*(Na is indeterminate. 81aaf70b23SDavid SchultzAlso, if the real or imaginary part of the input is finite and 82aaf70b23SDavid Schultzan \*(Na is generated, an invalid exception will be thrown. 83aaf70b23SDavid Schultz.Sh SEE ALSO 84aaf70b23SDavid Schultz.Xr cabs 3 , 85aaf70b23SDavid Schultz.Xr fenv 3 , 867161cdb3SJoel Dahl.Xr math 3 87aaf70b23SDavid Schultz.Sh STANDARDS 88aaf70b23SDavid SchultzThe 89511dd36bSDavid Schultz.Fn csqrt , 90511dd36bSDavid Schultz.Fn csqrtf , 91aaf70b23SDavid Schultzand 92511dd36bSDavid Schultz.Fn csqrtl 93aaf70b23SDavid Schultzfunctions conform to 94aaf70b23SDavid Schultz.St -isoC-99 . 95aaf70b23SDavid Schultz.Sh BUGS 96aaf70b23SDavid SchultzFor 97511dd36bSDavid Schultz.Fn csqrt 98511dd36bSDavid Schultzand 99511dd36bSDavid Schultz.Fn csqrtl , 100511dd36bSDavid Schultzinexact results are not always correctly rounded. 101