home *** CD-ROM | disk | FTP | other *** search
-
- /********************************************************************/
- /**** ****/
- /**** ****/
- /**** Program : UmwStoF UmwFtoS ****/
- /**** ****/
- /**** Version : 01.09 ****/
- /**** ****/
- /**** Erstversion : 21.05.1988 ****/
- /**** ****/
- /**** Letzte Änderung : 05.08.1990 ****/
- /**** ****/
- /**** Compiliert mit : siehe MAKEFILE ****/
- /**** ****/
- /**** Gelinkt mit : Für Tool.Library ****/
- /**** ****/
- /********************************************************************/
- /**** ****/
- /**** ****/
- /**** Copyright by Rüdiger Dreier ****/
- /**** ****/
- /**** ****/
- /********************************************************************/
-
-
- #include "ToolProto.h"
-
- /* Funktion, die den linken Teil eines Strings zurückgibt */
- VOID __asm left(register __a0 char *Ziel,
- register __a1 char *string,
- register __d0 LONG Anzahl)
- {
- int Lange;
- int i;
-
- Lange=strlen(string);
- if (Anzahl<=0 )
- {
- Ziel[0]=0;
- return;
- }
-
- if (((LONG)Lange)<Anzahl)Anzahl=(LONG)Lange;
- for(i=0;i<=Anzahl-1;i++)
- {
- Ziel[i]=string[i];
- }
- Ziel[i]=0;
- }
-
- /* Funktion gibt den rechten Teil des Strings zurück */
- VOID __asm right(register __a0 char *Ziel,
- register __a1 char *string,
- register __d0 LONG Anzahl)
- {
- int Lange;
- int i;
-
- Lange=strlen(string);
-
- if (Anzahl<=0 )
- {
- Ziel[0]=0;
- return;
- }
-
- if (Lange<Anzahl)Anzahl=Lange;
-
- for(i=0;i<=Anzahl-1;i++)
- {
- Ziel[i]=string[Lange-Anzahl+i];
- }
- Ziel[i]=0;
- }
-
-
- /* Funktion gibt Teil aus der Mitte zurück */
- VOID __asm mid(register __a0 char *Ziel,
- register __a1 char *string,
- register __d0 LONG Anfang,
- register __d1 LONG Anzahl)
- {
- int i;
- int Lange;
-
- Lange=strlen(string);
-
- if (Anzahl<=0 )
- {
- Ziel[0]=0;
- return;
- }
- if (Lange<Anzahl+Anfang)Anzahl=Lange-Anfang;
-
- for(i=Anfang;i<=Anfang+Anzahl-1;i++)
- {
- Ziel[i-Anfang]=string[i];
- }
- Ziel[i-Anfang]=0;
- }
-
-
- /* Wandelt String in DOUBLE um */
- VOID __asm UmwStoF(register __a0 DOUBLE *Ziel,
- register __a1 char *string)
- {
- char Mant[256],Exp[50];
- LONG a,Vorzeichen;
- DOUBLE Manti,Expo;
- DOUBLE Fehler;
-
- Fehler=0.0,Vorzeichen=0;
-
- a=stcisn(string,"ed");
- if(a>=28)
- {
- *Ziel=Fehler;
- return;
- }
- else
- {
- left(Mant,string,a);
- }
-
- a=strlen(string)-a-1;
- if(a>=8)
- {
- *Ziel=Fehler;
- return;
- }
- else
- {
- right(Exp,string,a);
- }
-
- if(strlen(Mant)==0 && strlen(Exp)!=0)
- {
- SHORT *a;
- a=(SHORT *)Mant;
- *a=0x3100;
- /* strcpy(Mant,"1"); */
- }
-
- a=stcisn(Exp,".");
- if(a!=strlen(Exp))
- {
- *Ziel=Fehler;
- return;
- }
-
- Manti=stof(Mant);
- Expo =stof(Exp);
- if(Tst(Expo)==-1)
- {
- Vorzeichen=1;
- Expo=Neg(Expo);
- }
- Expo=Pow(10.0,Expo);
- if(Vorzeichen==1)
- {
- Expo=Div(1.0,Expo);
- }
- Expo =Mul(Expo,Manti);
- *Ziel=Expo;
- }
-
-
- DOUBLE stof(char *string)
- {
- #define POS 0
- #define NEG 1
-
- DOUBLE Wert;
- DOUBLE Hilfe;
-
- int i,Vorz;
- i=0;
- Vorz=0;
- Wert=0.0;
- if(string[i]=='+')
- {
- Vorz=POS;
- i++;
- }
- if(string[i]=='-')
- {
- Vorz=NEG;
- i++;
- }
-
- while(string[i]!='.' && string[i]!=0)
- {
- LONG val;
- val=(string[i]-48L);
- if(val>=0 && val <=9)
- {
- Wert=Mul(10.0,Wert);
- Wert=Add(Flt(val),Wert);
- }
- i++;
- }
-
-
- if(string[i]==0)
- {
- if(Vorz)
- {
- Wert=Sub(0.0,Wert);
- }
- return(Wert);
- }
-
- i++;
-
- Hilfe=.1;
-
- while(string[i]!=0)
- {
- Wert=Add(Wert, Mul(Hilfe,Flt(((string[i]-48L)))));
- Hilfe=Div(Hilfe,10.0);
- i++;
- }
- if(Vorz)
- {
- Wert=Sub(0.0,Wert);
- }
- return(Wert);
- }
-
- extern struct Library *MathIeeeDoubBasBase;
- extern struct Library *MathIeeeDoubTransBase;
-
- VOID ftos(char *Ziel,
- DOUBLE Zahl,
- LONG Nachkomma)
- {
- /* Erhält Zahl ohne Vorzeichen und <10 */
- DOUBLE V;
- LONG i;
-
- for (i=1;i<=Nachkomma+1;i++)
- {
- V=Vorkomma(Zahl);
- Zahl=Sub(Zahl,V);
- Ziel[i-1]=48+Fix(V);
- Zahl=Mul(Zahl,10.0);
- }
- Ziel[i-1]=0;
- }
-
- VOID __asm UmwFtoS(register __a0 char *Ziel,
- register __a1 DOUBLE *Zahl1,
- register __d0 LONG Nachkomma)
- {
- DOUBLE Lange,Runden,Zahl;
- LONG Vorzeichen;
- char string[50],ZW[50];
- char ZW1[50];
-
- Zahl=*Zahl1;
-
- if(Vorzeichen=Tst(Zahl))
- {
- Zahl=Div(Zahl,Flt(Vorzeichen)); /* Zahl positiv */
- if(Cmp(Zahl,.9)==1)Zahl=Add(Zahl,.00000001); /* Runden für int */
- if(Cmp(Zahl,1e6)==1L)Zahl=Add(Zahl,1.0); /* Runden für int */
-
- Lange=Floor(Log10(Zahl)); /* Anzahl Vorkommastellen */
- Zahl=Div(Zahl,Pow(10.0,Lange)); /* Nur noch 1 Stelle vorm Komma */
- if(Cmp(Lange,3.0)<=0 && Cmp(Lange,-2.0)>=0)
- {
- Runden=Pow(10.0,Add(Flt(Nachkomma),Lange));
- Runden=Div(0.500001,Runden);
- Zahl=Add(Zahl,Runden);
- /* Durch Runden kann eine Stelle mehr entstanden sein, z.B. 0.99999999 */
- Runden=Add(Floor(Log10(Zahl)),.0001); /* Anzahl Vorkommastellen */
- if(Cmp(Runden,1.000000)==1)
- {
- Lange=Add(Lange,1.0000);
- Zahl=Div(Zahl,10.0);
- }
- ftos(string,Zahl,Nachkomma+Fix(Lange));
-
- left(ZW1,string,Fix(Lange)+1);
- strcpy(ZW,ZW1); /* Vorkommateil kopieren */
- strcat(ZW,".");
- if(!Cmp(Lange,-2.0))strcat(ZW,"0");
-
- right(ZW1,string,Nachkomma);
- strcat(ZW,ZW1); /* Nachkommateil kopieren */
- }
- else
- {
- LONG Vorzeichen;
- Runden=Pow(10.0,Flt(Nachkomma));
- Runden=Div(0.5001,Runden);
- Zahl=Add(Zahl,Runden);
-
- ftos(string,Zahl,Nachkomma);
-
- left(ZW,string,1); /* Vorkommateil kopieren */
- strcat(ZW,".");
-
- right(ZW1,string,Nachkomma);
- strcat(ZW,ZW1); /* Nachkommateil kopieren */
- strcat(ZW,"d");
- Zahl=Lange;
-
- if(Vorzeichen=Tst(Zahl))
- {
- Zahl=Div(Zahl,Flt(Vorzeichen)); /* Exponent posivit */
- }
- if(Cmp(Zahl,.9)==1)Zahl=Add(Zahl,.0000000001); /* Runden für int */
- Runden=Floor(Log10(Zahl));
- Nachkomma=Fix(Runden); /* Nachkomma enthält den Exponenten */
-
- Lange=Floor(Log10(Zahl)); /* Länge des Exponenten */
- Zahl=Div(Zahl,Pow(10.0,Lange));
- ftos(string,Zahl,Nachkomma);
- if(Vorzeichen==-1)strcat(ZW,"-");
- strcat(ZW,string);
- }
- if(Vorzeichen==-1)
- {
- SHORT *a;
- a=(SHORT *)string;
- *a=0x2d00;
- /* strcpy(string,"-"); */
- strcat(string,ZW);
- }
- else
- {
- strcpy(string,ZW);
- }
- }
- else
- {
- SHORT *a;
- a=(SHORT *)string;
- *a=0x3000;
- /*strcpy(string,"0");*/
- }
- strcpy(Ziel,string);
- }
-
- DOUBLE Vorkomma(DOUBLE Zahl)
- {
- LONG Int;
-
- Int=Fix(Zahl);
- Zahl=Flt(Int);
- return(Zahl);
- }
-
-