From 98b9ac8e98e12896506042af97cbdee127d975da Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 13 Sep 2019 15:11:38 +0200 Subject: [PATCH] mescc: Mes C Library: Support gcc-4.6.4: Add math stubs. * lib/math/ceil.c: New file. * lib/math/floor.c: New file. * lib/stub/atan2.c: New file. * lib/stub/cos.c: New file. * lib/stub/exp.c: New file. * lib/stub/log.c: New file. * lib/stub/modf.c: New file. * lib/stub/pow.c: New file. * lib/stub/sin.c: New file. * lib/stub/sqrt.c: New file. * lib/libc+gnu.c: Include them. * include/math.h (atan2, ceil, cos, exp, fabs, floor, log, modf, pow, sin, sqrt): Declare. * lib/math/fabs.c: Update. * lib/stub/ldexp.c: Update. --- build-aux/configure-lib.sh | 10 ++++++++++ include/math.h | 12 ++++++++++++ lib/math/ceil.c | 29 +++++++++++++++++++++++++++++ lib/math/fabs.c | 4 ++-- lib/math/floor.c | 29 +++++++++++++++++++++++++++++ lib/stub/atan2.c | 32 ++++++++++++++++++++++++++++++++ lib/stub/cos.c | 32 ++++++++++++++++++++++++++++++++ lib/stub/exp.c | 32 ++++++++++++++++++++++++++++++++ lib/stub/ldexp.c | 4 ++-- lib/stub/log.c | 32 ++++++++++++++++++++++++++++++++ lib/stub/modf.c | 32 ++++++++++++++++++++++++++++++++ lib/stub/pow.c | 32 ++++++++++++++++++++++++++++++++ lib/stub/sin.c | 32 ++++++++++++++++++++++++++++++++ lib/stub/sqrt.c | 32 ++++++++++++++++++++++++++++++++ 14 files changed, 340 insertions(+), 4 deletions(-) create mode 100644 lib/math/ceil.c create mode 100644 lib/math/floor.c create mode 100644 lib/stub/atan2.c create mode 100644 lib/stub/cos.c create mode 100644 lib/stub/exp.c create mode 100644 lib/stub/log.c create mode 100644 lib/stub/modf.c create mode 100644 lib/stub/pow.c create mode 100644 lib/stub/sin.c create mode 100644 lib/stub/sqrt.c diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index 11ce436d..7568de8d 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -228,7 +228,9 @@ lib/dirent/__getdirentries.c lib/dirent/closedir.c lib/dirent/opendir.c lib/dirent/readdir.c +lib/math/ceil.c lib/math/fabs.c +lib/math/floor.c lib/mes/fdgets.c lib/posix/alarm.c lib/posix/execl.c @@ -266,9 +268,12 @@ lib/string/strncat.c lib/string/strpbrk.c lib/string/strspn.c lib/stub/__cleanup.c +lib/stub/atan2.c lib/stub/bsearch.c lib/stub/chown.c +lib/stub/cos.c lib/stub/ctime.c +lib/stub/exp.c lib/stub/fpurge.c lib/stub/freadahead.c lib/stub/frexp.c @@ -280,9 +285,12 @@ lib/stub/getpgrp.c lib/stub/getpwnam.c lib/stub/getpwuid.c lib/stub/gmtime.c +lib/stub/log.c lib/stub/mktime.c +lib/stub/modf.c lib/stub/pclose.c lib/stub/popen.c +lib/stub/pow.c lib/stub/rand.c lib/stub/rewind.c lib/stub/setbuf.c @@ -293,6 +301,8 @@ lib/stub/sigaddset.c lib/stub/sigblock.c lib/stub/sigdelset.c lib/stub/sigsetmask.c +lib/stub/sin.c +lib/stub/sqrt.c lib/stub/strftime.c lib/stub/sys_siglist.c lib/stub/system.c diff --git a/include/math.h b/include/math.h index adf3ceb8..2e2ca985 100644 --- a/include/math.h +++ b/include/math.h @@ -24,8 +24,20 @@ #undef __MES_MATH_H #include_next #else // ! SYSTEM_LIBC + +double atan2 (double y, double x); +double ceil (double x); +double cos (double x); +double exp (double x); double fabs (double number); +double floor (double x); double ldexp (double value, int exponent); +double log (double x); +double modf (double value, double *integer_part); +double pow (double base, double power); +double sin (double x); +double sqrt (double x); + #endif // ! SYSTEM_LIBC #endif // __MES_MATH_H diff --git a/lib/math/ceil.c b/lib/math/ceil.c new file mode 100644 index 00000000..bd3ceba4 --- /dev/null +++ b/lib/math/ceil.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +double +ceil (double number) +{ + long i = number + 0.9999; + number = i; + return number; +} diff --git a/lib/math/fabs.c b/lib/math/fabs.c index 5726c728..21fa59a0 100644 --- a/lib/math/fabs.c +++ b/lib/math/fabs.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -18,7 +18,7 @@ * along with GNU Mes. If not, see . */ -//#include +#include double fabs (double number) diff --git a/lib/math/floor.c b/lib/math/floor.c new file mode 100644 index 00000000..982694ab --- /dev/null +++ b/lib/math/floor.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +double +floor (double number) +{ + long i = number; + number = i; + return number; +} diff --git a/lib/stub/atan2.c b/lib/stub/atan2.c new file mode 100644 index 00000000..09e691b8 --- /dev/null +++ b/lib/stub/atan2.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include + +double +atan2 (double x, double y) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("atan2 stub\n"); + stub = 1; + return 0; +} diff --git a/lib/stub/cos.c b/lib/stub/cos.c new file mode 100644 index 00000000..1b183c8f --- /dev/null +++ b/lib/stub/cos.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include + +double +cos (double x) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("cos stub\n"); + stub = 1; + return 0; +} diff --git a/lib/stub/exp.c b/lib/stub/exp.c new file mode 100644 index 00000000..be19b95e --- /dev/null +++ b/lib/stub/exp.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include + +double +exp (double x) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("exp stub\n"); + stub = 1; + return 0; +} diff --git a/lib/stub/ldexp.c b/lib/stub/ldexp.c index d7c4c071..11efe025 100644 --- a/lib/stub/ldexp.c +++ b/lib/stub/ldexp.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -22,7 +22,7 @@ #include double -ldexp (double x, int exp) +ldexp (double value, int exponent) { static int stub = 0; if (__mes_debug () && !stub) diff --git a/lib/stub/log.c b/lib/stub/log.c new file mode 100644 index 00000000..110f4e28 --- /dev/null +++ b/lib/stub/log.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include + +double +log (double x) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("log stub\n"); + stub = 1; + return 0; +} diff --git a/lib/stub/modf.c b/lib/stub/modf.c new file mode 100644 index 00000000..eaa860e2 --- /dev/null +++ b/lib/stub/modf.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include + +double +modf (double value, double *integer_part) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("modf stub\n"); + stub = 1; + return 0; +} diff --git a/lib/stub/pow.c b/lib/stub/pow.c new file mode 100644 index 00000000..bd18f28f --- /dev/null +++ b/lib/stub/pow.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include + +double +pow (double base, double power) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("pow stub\n"); + stub = 1; + return 0; +} diff --git a/lib/stub/sin.c b/lib/stub/sin.c new file mode 100644 index 00000000..3cc81cc7 --- /dev/null +++ b/lib/stub/sin.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include + +double +sin (double x) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("sin stub\n"); + stub = 1; + return 0; +} diff --git a/lib/stub/sqrt.c b/lib/stub/sqrt.c new file mode 100644 index 00000000..fc432290 --- /dev/null +++ b/lib/stub/sqrt.c @@ -0,0 +1,32 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2019 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include +#include + +double +sqrt (double x) +{ + static int stub = 0; + if (__mes_debug () && !stub) + eputs ("sqrt stub\n"); + stub = 1; + return 0; +}