delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2015/05/18/13:19:59

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Recipient: djgpp AT delorie DOT com
Message-ID: <555A2D8F.8010004@gmx.de>
Date: Mon, 18 May 2015 20:21:03 +0200
From: "Juan Manuel Guerrero (juan DOT guerrero AT gmx DOT de)" <djgpp AT delorie DOT com>
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.13) Gecko/20101206 SUSE/3.1.7 Thunderbird/3.1.7
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Order of arguments passed to sincos changed.
X-Provags-ID: V03:K0:wx8Ld1Yn33syo6pfby26j4pM7VarkyDdo4MrTKF3G5n/Gb/guJw
gaW4+oiQAwTkTZuLHOWO8QiFmzcfF4+8ob3tUgAcDgyojwKurCL8PFv5xRfb+j/1+f8eK5c
3Noia5cgF+P8xOa+f+hqMqbs5TTnTOV38rWmwkVWM9jHcRZM000ZLFFfZbdlBceF+TP2fNq
+6w3qXhh/uJrxkaOQlIBQ==
X-UI-Out-Filterresults: notjunk:1;
Reply-To: djgpp AT delorie DOT com

I have changed the order of the arguments passed to the sincos function to
match the order used by the function version implemented on GNU systems.
IOW I changed:
old DJGPP order:  void   sincos(double *_cos, double *_sin, double _x)
to
new DJGPP order:  void   sincos(double _x, double *_sin, double *_cos)

I have also added an small test program into tests/libc/compat/math.

If I get not objection in a rasonable period of time I will apply the patch.


Regards,
Juan M. Guerrero






2015-05-17  Juan Manuel Guerrero  <juan DOT guerrero AT gmx DOT de>


	* djgpp/include/math.h:  Order of arguments of sincos function changed to
	the order used by GNU systems.

	* djgpp/src/libc/compat/math/sincos.S:  Order of arguments of sincos function
	changed to the order used by GNU systems.

	* djgpp/src/libc/compat/math/sincos.txh:  Order of arguments of sincos function
	changed to the order used by GNU systems.

	* djgpp/tests/libc/compat/math/makefile:  sincos test program added.

	* djgpp/tests/libc/compat/math/sincos.c:  sincos test program added.






diff -aprNU5 djgpp.orig/include/math.h djgpp/include/math.h
--- djgpp.orig/include/math.h	2013-11-16 21:44:06 +0000
+++ djgpp/include/math.h	2015-05-18 00:51:30 +0000
@@ -256,11 +256,11 @@ extern int finitel(long double);

  double exp10(double _x);
  double pow10(double _x);
  double pow2(double _x);
  double powi(double _base, int _exp);
-void   sincos(double *_cos, double *_sin, double _x);
+void   sincos(double _x, double *_sin, double *_cos);

  /* These are in libm.a (Cygnus).  You must link -lm to get these */
  /* See libm/math.h for comments */

  #ifndef __cplusplus
diff -aprNU5 djgpp.orig/src/docs/kb/wc205.txi djgpp/src/docs/kb/wc205.txi
--- djgpp.orig/src/docs/kb/wc205.txi	2015-05-18 00:37:40 +0000
+++ djgpp/src/docs/kb/wc205.txi	2015-05-18 00:55:54 +0000
@@ -37,5 +37,9 @@ lookup failure when @env{LD_LIBRARY_PATH
  @cindex @file{dir.h},  fixed a wrong structure packing directive
  @file{dir.h}: Fixed a wrong structure packing directive (bug introduced by
  djgpp-v2.01 back in 1996) that would infect other sources and headers with
  potentially adverse effects. NOTE: You might want to recompile your libraries.

+@cindex @file{math.h}, order of arguments of @code{sincos} changed
+@findex sincos AT r{, order of arguments of @code{sincos} changed}
+The Order of arguments passed to the @code{sincos} function has been changed to
+match the order used by the function version as implemented in @acronym{GNU} systems.
diff -aprNU5 djgpp.orig/src/libc/compat/math/sincos.S djgpp/src/libc/compat/math/sincos.S
--- djgpp.orig/src/libc/compat/math/sincos.S	2011-04-17 18:45:26 +0000
+++ djgpp/src/libc/compat/math/sincos.S	2015-05-18 00:51:30 +0000
@@ -1,25 +1,26 @@
+/* Copyright (C) 2015 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2011 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  NaN:
  	.long	0x00000000, 0xFFF80000

  	.globl	_sincos
  _sincos:

-	/* void sincos(double *cosine, double *sine, double x); */
+	/* void sincos(double x, double *sine, double *cosine); */

-	movl	16(%esp), %ecx
+	movl	8(%esp), %ecx

-	movl	4(%esp), %eax		/* Point to cosine. */
-	movl	8(%esp), %edx		/* Point to sine. */
+	movl	12(%esp), %edx		/* Point to sine. */
+	movl	16(%esp), %eax		/* Point to cosine. */

  	andl	$0x7FF00000, %ecx	/* Examine exponent of x. */
  	cmpl	$0x43E00000, %ecx	/* |x| >= 2^63 */
  	jae	bigarg

-	fldl	12(%esp)
+	fldl	4(%esp)
  	fsincos
  	fstpl	(%eax)			/* cos */
  	fstpl	(%edx)			/* sin */
  	ret

diff -aprNU5 djgpp.orig/src/libc/compat/math/sincos.txh djgpp/src/libc/compat/math/sincos.txh
--- djgpp.orig/src/libc/compat/math/sincos.txh	2003-01-29 12:32:16 +0000
+++ djgpp/src/libc/compat/math/sincos.txh	2015-05-18 00:51:30 +0000
@@ -4,11 +4,11 @@
  @subheading Syntax

  @example
  #include <math.h>

-void   sincos(double *cosine, double *sine, double x);
+void   sincos(double x, double *sine, double *cosine);
  @end example

  @subheading Description

  This function computes the cosine and the sine of @var{x} in a single
diff -aprNU5 djgpp.orig/tests/libc/compat/math/makefile djgpp/tests/libc/compat/math/makefile
--- djgpp.orig/tests/libc/compat/math/makefile	1970-01-01 00:00:00 +0000
+++ djgpp/tests/libc/compat/math/makefile	2015-05-18 00:51:30 +0000
@@ -0,0 +1,5 @@
+TOP=../..
+
+SRC += sincos.c
+
+include $(TOP)/../makefile.inc
diff -aprNU5 djgpp.orig/tests/libc/compat/math/sincos.c djgpp/tests/libc/compat/math/sincos.c
--- djgpp.orig/tests/libc/compat/math/sincos.c	1970-01-01 00:00:00 +0000
+++ djgpp/tests/libc/compat/math/sincos.c	2015-05-18 00:51:30 +0000
@@ -0,0 +1,78 @@
+#include <math.h>
+#include <stdio.h>
+
+static double argument[] = {
+  -1.5707963267948966192313216916398L,  /* -90 degree.  */
+  -1.3089969389957471826927680763665L,  /* -75 degree.  */
+  -1.0471975511965977461542144610932L,  /* -60 degree.  */
+  -0.7853981633974483096156608458199L,  /* -45 degree.  */
+  -0.5235987755982988730771072305466L,  /* -30 degree.  */
+  -0.2617993877991494365385536152733L,  /* -15 degree.  */
+  +0.0000000000000000000000000000000L,  /* +0  degree.  */
+  +0.2617993877991494365385536152733L,  /* +15 degree.  */
+  +0.5235987755982988730771072305466L,  /* +30 degree.  */
+  +0.7853981633974483096156608458199L,  /* +45 degree.  */
+  +1.0471975511965977461542144610932L,  /* +60 degree.  */
+  +1.3089969389957471826927680763665L,  /* +75 degree.  */
+  +1.5707963267948966192313216916398L,  /* +90 degree.  */
+  +2.0943951023931954923084289221863L,  /* +120 degree. */
+  +2.6179938779914943653855361527329L,  /* +150 degree. */
+  +3.1415926535897932384626433832795L,  /* +180 degree. */
+  +3.1415926535897932384626433832795L,  /* +180 degree. */
+  +3.9269908169872415480783042290994L,  /* +225 degree. */
+  +4.7123889803846898576939650749193L,  /* +270 degree. */
+  +5.4977871437821381673096259207391L,  /* +315 degree. */
+  +6.283185307179586476925286766559L,   /* +360 degree. */
+};
+
+static double should_be[][2] = {
+  /*   sine value        cosine value   */
+  {-1.000000000000000, 0.000000000000000},
+  {-0.965925826289068, 0.258819045102521},
+  {-0.866025403784439, 0.500000000000000},
+  {-0.707106781186547, 0.707106781186548},
+  {-0.500000000000000, 0.866025403784439},
+  {-0.258819045102521, 0.965925826289068},
+  {0.000000000000000, 1.000000000000000},
+  {0.258819045102521, 0.965925826289068},
+  {0.500000000000000, 0.866025403784439},
+  {0.707106781186547, 0.707106781186548},
+  {0.866025403784439, 0.500000000000000},
+  {0.965925826289068, 0.258819045102521},
+  {1.000000000000000, 0.000000000000000},
+  {0.866025403784439, -0.500000000000000},
+  {0.500000000000000, -0.866025403784439},
+  {0.000000000000000, -1.000000000000000},
+  {0.000000000000000, -1.000000000000000},
+  {-0.707106781186547, -0.707106781186548},
+  {-1.000000000000000, -0.000000000000000},
+  {-0.707106781186548, 0.707106781186547},
+  {-0.000000000000000, 1.000000000000000}
+};
+
+static const size_t n_test_arguments = sizeof(argument) / sizeof(argument[0]);
+
+
+int main(void)
+{
+  unsigned int i, error_couter;
+
+  for (error_couter = i = 0; i < n_test_arguments; i++)
+  {
+    double sv, cv;
+    sincos(argument[i], &sv, &cv);
+    if (fabs(sv - should_be[i][0]) > 1.E-15 || fabs(cv - should_be[i][1]) > 1.E-15)
+    {
+      printf("sincos failed for %.15f\n"
+             "returned values: sine value   = %.15f,  should be = %.15f\n"
+             "                 cosine value = %.15f,  should be = %.15f\n",
+             argument[i], sv, should_be[i][0], cv, should_be[i][1]);
+      error_couter++;
+    }
+  }
+
+  if (error_couter == 0)
+    printf("test passed.\n");
+
+  return error_couter;
+}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019