standards/82654: C99 long double math functions are missing

Steven G. Kargl kargl at troutmask.apl.washington.edu
Sun Jun 26 17:10:19 GMT 2005


The following reply was made to PR standards/82654; it has been noted by GNATS.

From: "Steven G. Kargl" <kargl at troutmask.apl.washington.edu>
To: FreeBSD-gnats-submit at FreeBSD.org, freebsd-standards at FreeBSD.org
Cc:  
Subject: Re: standards/82654: C99 long double math functions are missing
Date: Sun, 26 Jun 2005 10:00:57 -0700 (PDT)

 --ELM1119805257-98328-0_
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain; charset=US-ASCII
 
 FreeBSD-gnats-submit at FreeBSD.org wrote:
 
 > >Category:       standards
 > >Responsible:    freebsd-standards
 > >Synopsis:       C99 long double math functions are missing
 > >Arrival-Date:   Sat Jun 25 23:40:12 GMT 2005
 > 
 
 The attached files implement hypotl() and cabsl().  The
 documentation has been updated.  Note hypot(3) manpage
 refers to a non-existent cabs.c file.
 
 -- 
 Steve
 http://troutmask.apl.washington.edu/~kargl/
 
 --ELM1119805257-98328-0_
 Content-Transfer-Encoding: 7bit
 Content-Type: text/x-c++src
 Content-Disposition: attachment; filename=hypotl.c
 Content-Description: 
 
 /*-
  * Copyright (c) 2005, Steven G. Kargl
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  * 1. Redistributions of source code must retain the above copyright
  *    notice unmodified, this list of conditions, and the following
  *    disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 /*
  *  Compute the hypot(x,y) = sqrt(x*x+y*y) for long double x and y.
  */
 
 #include <math.h>
 
 long double sqrtl(long double);
 
 static long double zero = 0.0L;
 
 long double hypotl(long double x, long double y) {
 
 	long double ax, ay;
 		
 	/* If x or y is a +-Inf, return +Inf. */
 	if (isinf(x) || isinf(y))
 		return (-1.L / zero);
 
 	/* If x or y is a NaN, return NaN. */
 	if (isnan(x) || isnan(y))
 		return (x*x+x) + (y*y+y);
 
 	ax = fabsl(x);
 	ay = fabsl(y);
 
 	/* Special case if x and/or y is zero. */
 	if (ax == zero || ay == zero)
 		return (ay + ax);
 
 	/* Avoid overflow in sqrtl(x*x + y*y) */
 	if (ax >= ay) {
 		ay /= ax;
 		ax = ax * sqrtl(1.0L + ay * ay);
 	} else {
 		ax /= ay;
 		ax = ay * sqrtl(ax * ax + 1.0L);
 	}
 
 	return ax;
 
 }
 
 --ELM1119805257-98328-0_
 Content-Transfer-Encoding: 7bit
 Content-Type: text/x-c++src
 Content-Disposition: attachment; filename=cabsl.c
 Content-Description: 
 
 /*-
  * Copyright (c) 2005, Steven G. Kargl
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  * 1. Redistributions of source code must retain the above copyright
  *    notice unmodified, this list of conditions, and the following
  *    disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 /*
  * Compute the absolute value of a long double complex argument via a
  * call to hypotl().
  */
 
 #include <complex.h>
 #include <math.h>
 
 long double cabsl(long double complex z) {
 
 	return hypotl(creall(z), cimagl(z));
 }
 
 --ELM1119805257-98328-0_
 Content-Transfer-Encoding: 7bit
 Content-Type: text/x-patch
 Content-Disposition: attachment; filename=hypot.3.diff
 Content-Description: 
 
 --- hypot.3.orig	Sun Jun 26 09:46:01 2005
 +++ hypot.3	Sun Jun 26 09:53:20 2005
 @@ -38,8 +38,10 @@
  .Sh NAME
  .Nm hypot ,
  .Nm hypotf ,
 +.Nm hypotl ,
  .Nm cabs ,
 -.Nm cabsf
 +.Nm cabsf ,
 +.Nm cabsl
  .Nd Euclidean distance and complex absolute value functions
  .Sh LIBRARY
  .Lb libm
 @@ -49,25 +51,31 @@
  .Fn hypot "double x" "double y"
  .Ft float
  .Fn hypotf "float x" "float y"
 +.Ft "long double"
 +.Fn hypotl "long double x" "long double y"
  .In complex.h
  .Ft double
  .Fn cabs "double complex z"
  .Ft float
  .Fn cabsf "float complex z"
 +.Ft "long double"
 +.Fn cabsl "long double complex z"
  .Sh DESCRIPTION
  The
 -.Fn hypot
 +.Fn hypot ,
 +.Fn hypotf ,
  and
 -.Fn hypotf
 +.Fn hypotl
  functions
  compute the
  sqrt(x*x+y*y)
  in such a way that underflow will not happen, and overflow
  occurs only if the final result deserves it.
  The
 -.Fn cabs
 +.Fn cabs ,
 +.Fn cabsf ,
  and
 -.Fn cabsf
 +.Fn cabsl
  functions compute the complex absolute value of
  .Fa z .
  .Pp
 
 --ELM1119805257-98328-0_--


More information about the freebsd-standards mailing list