URL
https://opencores.org/ocsvn/1664/1664/trunk
[/] [1664/] [trunk/] [c/] [lista/] [fl2__cadena.c] - Blame information for rev 2
Details |
Compare with Previous |
View Log
Line No. |
Rev |
Author |
Line |
1 |
2 |
mrdmkg |
#include "tipodef.h"
|
2 |
|
|
|
3 |
|
|
fl2 fl2__cadena(n1 *cadena,nN cuantia)
|
4 |
|
|
{
|
5 |
|
|
if(cuantia==0) return 0.0;
|
6 |
|
|
n1 sinia_entero=0,sinia_potia=0;
|
7 |
|
|
if (*cadena=='-') { cadena++; cuantia--; sinia_entero=1; }
|
8 |
|
|
n1 *cadena_frato=0,*cadena_potia=0;
|
9 |
|
|
nN cuantia_cadena_frato=0,cuantia_cadena_entero=cuantia,cuantia_cadena_potia=0;
|
10 |
|
|
nN indise;
|
11 |
|
|
|
12 |
|
|
for(indise=0;indise<cuantia;indise++)
|
13 |
|
|
{
|
14 |
|
|
if(cadena[indise]=='.'){cadena_frato=cadena+indise+1; cuantia_cadena_entero=indise; break;}
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
if (cadena_frato!=0)
|
18 |
|
|
{
|
19 |
|
|
for(cuantia_cadena_frato=0;cuantia_cadena_frato<(cuantia-(cadena_frato-cadena));cuantia_cadena_frato++)
|
20 |
|
|
{
|
21 |
|
|
if((cadena_frato[cuantia_cadena_frato]|0x20)=='e')
|
22 |
|
|
{
|
23 |
|
|
cadena_potia=cadena_frato+cuantia_cadena_frato+1;
|
24 |
|
|
if(*cadena_potia=='-') { cadena_potia++; sinia_potia=1; }
|
25 |
|
|
cuantia_cadena_potia=cuantia-(cadena_potia-cadena);
|
26 |
|
|
break;
|
27 |
|
|
}
|
28 |
|
|
}
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
fl2 fl=0.0;
|
32 |
|
|
sN potia=0;
|
33 |
|
|
sN i;
|
34 |
|
|
for(i=0;i<cuantia_cadena_entero;i++){ fl=(fl*10.0)+(fl2)(cadena[i]&0x0f); }
|
35 |
|
|
for(i=0;i<cuantia_cadena_frato;i++){ fl=(fl*10.0)+(fl2)(cadena_frato[i]&0x0f); }
|
36 |
|
|
if(sinia_entero!=0){ fl*=-1.0; }
|
37 |
|
|
for(i=0;i<cuantia_cadena_potia;i++){ potia=(potia*10)+(cadena_potia[i]&0x0f); }
|
38 |
|
|
if(sinia_potia!=0){ potia=-potia; }
|
39 |
|
|
potia-=cuantia_cadena_frato;
|
40 |
|
|
for(i=0;i<potia;i++){ fl*=10.0; }
|
41 |
|
|
for(i=0;i>potia;i--){ fl*=0.1; }
|
42 |
|
|
return fl;
|
43 |
|
|
}
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.