Habe mal alle Mathroutinen und Floatroutinen ausprobiert vom "z88dk". Sie funktioniren alle mit den richtigen Werten ohne absturz, auch bei der Ausgabe auf dem Screen mit "printf".
In den letzten 6 Monaten haben die Programmierer schön rangeklotzt damit es funktioniert.
Zusätzlich mit Grafik, sternförmig werden Linien im Kreis gezeichnet :
C
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <math.h>
#include <graphics.h>
#pragma -zorg=16384
void main(){
float x,xg,yg;
int xgg,ygg;
for (x=0.0; x<360.0; x=x+3.0)
{
xg=sin(x*pi()/180.0)*80;
yg=cos(x*pi()/180.0)*80;
xgg=xg;
ygg=yg;
draw(160,100,160+xgg,100+ygg);
}
}
Alles anzeigen
Werte 4stellig ausgeben 43x (geprüft, 100%tig genau) :
C
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <math.h>
#pragma -zorg=16384
void main(){
float x;
double wert;
unsigned char text[15];
char c;
for (x=0.0; x<43.0; x=x+1.2)
{
wert=cos(1.234) * x * pi();
ftoa(wert,4,text);
printf(text);
printf("\n");
}
printf("\n");
printf("fertig...");
c=getchar();
}
Alles anzeigen
Die Mathroutinen:
Code
/* $Id: math.h,v 1.11 2008/03/14 12:23:57 stefano Exp $ */
extern double __LIB__ acos(double); /* arc cosine */
extern double __LIB__ asin(double); /* arc cosine */
extern double __LIB__ atan(double); /* arc tangent */
extern double __LIB__ atan2(double,double); /* atan2(a,b) = arc tangent of a/b */
extern double __LIB__ cos(double); /* cosine */
extern double __LIB__ cosh(double); /* hyperbolic cosine */
extern double __LIB__ exp(double); /* exponential */
extern double __LIB__ log(double); /* natural logarithm */
extern double __LIB__ log10(double); /* log base 10 */
extern double __LIB__ pi(); /* greek pi */
extern double __LIB__ pow(double,double); /* pow(x,y) = x**y */
extern double __LIB__ sin(double); /* sine */
extern double __LIB__ sinh(double); /* hyperbolic sine */
extern double __LIB__ sqrt(double); /* square root */
extern double __LIB__ tan(double); /* tangent */
extern double __LIB__ tanh(double); /* hyperbolic tangent */
#ifndef _HAVE_ATOF_
#define _HAVE_ATOF_
extern double __LIB__ atof(char *);
#endif
/* Some additional CPC only routines now */
#if __CPC__ && __NATIVE_MATH__
extern double __LIB__ pow10(int x); /* pow(10,x) - CPC only */
extern void __LIB__ deg();
extern void __LIB__ rad();
#else
#define pow10(x) pow(10.,x)
#define deg(x) (x*180./pi())
#define rad(x) (x*pi()/180.)
#endif
/* More (unoptimized) functions */
#define cbrt(x) pow(x,.3333333)
#define ldexp(x,y) (pow(2.,(int)(y))*x)
#define hypot(x,y) sqrt(x*x+y*y)
#define asinh(x) log(2.*fabs(x)+1./(sqrt(x*x+1.)+fabs(x)))
#define acosh(x) log(2.*x-1./(x+sqrt(x*x-1.)))
#define log1p(x) log(1.+x)
#define expm1(x) (exp(x)-1.)
#endif /* _MATH_H */
Alles anzeigen
Die Floatroutinen:
Code
#ifndef __FLOAT_H__
#define __FLOAT_H__
/*
* Some more floating point routines..I can't remember
* why these are separated out..
*
* $Id: float.h,v 1.7 2003/08/22 21:14:40 dom Exp $
*/
extern double __LIB__ fmod();
extern double __LIB__ amax(double,double);
extern double __LIB__ fabs(double);
extern double __LIB__ amin(double,double);
extern double __LIB__ floor(double);
extern double __LIB__ ceil(double);
extern double __LIB__ fprand(void); /* Generic only */
extern double __LIB__ __FASTCALL__ zfloat(int);
extern int __LIB__ fpseed(double); /* Seed random number */
#ifndef _HAVE_ATOF_
#define _HAVE_ATOF_
extern double __LIB__ atof(char *);
#endif
/*
* Some support routines for floating point printf
*/
extern void __LIB__ ftoa(double, int, char *);
extern void __LIB__ ftoe(double, int, char *);
/*
* Some constant nicked from /usr/include/math.h
*/
# define M_E 2.7182818284590452354 /* e */
# define M_LOG2E 1.4426950408889634074 /* log_2 e */
# define M_LOG10E 0.43429448190325182765 /* log_10 e */
# define M_LN2 0.69314718055994530942 /* log_e 2 */
# define M_LN10 2.30258509299404568402 /* log_e 10 */
# define M_PI 3.14159265358979323846 /* pi */
# define M_PI_2 1.57079632679489661923 /* pi/2 */
# define M_PI_4 0.78539816339744830962 /* pi/4 */
# define M_1_PI 0.31830988618379067154 /* 1/pi */
# define M_2_PI 0.63661977236758134308 /* 2/pi */
# define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
# define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
# define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
#endif
Alles anzeigen
[/code]