mathstubs.c
1 /******************************************************************** 2 * Description: mathstubs.c 3 * Stubs for 'errno' and some error printing functions 4 * in the math library that don't exist in the kernel. 5 * 6 * Author: Paul_C - Derived from a file by Fred Proctor. 7 * Created at: Mon Feb 16 21:08:44 GMT 2004 8 * Computer: Morphix 9 * System: Linux 10 * 11 * Copyright (c) 2004 All rights reserved. 12 * 13 * Last change: 14 ********************************************************************/ 15 /* 16 * This program is free software; you can redistribute it and/or modify 17 * it under the terms of the GNU General Public License as published by 18 * the Free Software Foundation; either version 2 of the License, or 19 * (at your option) any later version. 20 * 21 * This program is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * GNU General Public License for more details. 25 * 26 * You should have received a copy of the GNU General Public License 27 * along with this program; if not, write to the Free Software 28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 29 */ 30 31 #include <linux/types.h> /* u_int16_t */ 32 #include "rtapi_math.h" 33 34 int stderr; 35 36 int fputs(const char *str) 37 { 38 return 0; 39 } 40 41 unsigned int fwrite(const void *ptr, unsigned int size, unsigned int nobj, 42 void *stream) 43 { 44 return nobj; 45 } 46 47 static int errno; 48 49 int *__errno_location(void) 50 { 51 return &errno; 52 } 53 54 void __assert_fail(const char *s, const char *file, unsigned int line, 55 const char *function) 56 { 57 return; 58 } 59 60 #ifndef isnan 61 int isnan(double x) 62 { 63 /* Return zero if x is a real number. */ 64 int a; 65 /* According to notes, a floating point number consists of 8 bytes. 66 Expressed as a 64 bit No. the sign will be B63. If bits 52-62 equal 67 0x7FF and bits 0-61 are non-zero, the number is a NaN. If bits 52-62 68 equal 0x7FF and bits 0-61 are zero, the number is infinite. An infinite 69 number will still cause errors so it should be safe to flag it as a 70 NaN. */ 71 u_int16_t *c = (u_int16_t *) & x; 72 a = c[3] & 0x7FF0; 73 return (a == 0x7FF0); 74 } 75 #endif 76 77 #ifndef __isnan 78 int __isnan(double x) 79 { /* There must be a better way of doing this ! 80 */ 81 int a; 82 u_int16_t *c = (u_int16_t *) & x; 83 a = c[3] & 0x7FF0; 84 return (a == 0x7FF0); 85 } 86 #endif 87 88 int RTdummy(void) 89 { 90 return stderr; 91 }