Velocity Reviews > Negative Value

# Negative Value

mdeh
Guest
Posts: n/a

 11-08-2007
Hi Everyone,
Tried to post via Google..which once again seems to be fritzed...so
please excuse if 2 posts show up.

I am trying to understand why I am not getting a negative value back,
using my version of atof

given the argument "-36.63"

double atof ( char *s){
double d = 0.00;
double sign = 1.00;
double fractprt = 1.00;
/* check for neg number */
if ( *s == '-') {
sign = -1.00;
s++;
}

d=d*10.00 + ('0' - *s++);
}
if (*s == '.'){
s++;
d=d*10.00 + ('0' - *s++);
fractprt *=10;
}
}

return (sign * d / fractprt) ;

}

I get 36.03, not -36.03.

mdeh
Guest
Posts: n/a

 11-08-2007
In article <(E-Mail Removed)>,
mdeh <(E-Mail Removed)> wrote:

> Hi Everyone,
> Tried to post via Google..which once again seems to be fritzed...so
> please excuse if 2 posts show up.
>
> I am trying to understand why I am not getting a negative value back,
> using my version of atof
>
> given the argument "-36.63"
>
> double atof ( char *s){
> double d = 0.00;
> double sign = 1.00;
> double fractprt = 1.00;
> /* check for neg number */
> if ( *s == '-') {
> sign = -1.00;
> s++;
> }
>
> d=d*10.00 + ('0' - *s++);
> }
> if (*s == '.'){
> s++;
> d=d*10.00 + ('0' - *s++);
> fractprt *=10;
> }
> }
>
> return (sign * d / fractprt) ;
>
> }
>
> I get 36.03, not -36.03.
>

This is going from Bad to Worse!!

Using a News-Watcher which required authentication to post...giving the
false ( !apparently!) impression that the article was not posted.

I really only want one answer!!!

CBFalconer
Guest
Posts: n/a

 11-08-2007
mdeh wrote:
>
> I am trying to understand why I am not getting a negative value
> back, using my version of atof
>
> given the argument "-36.63"
>
> double atof ( char *s){
> double d = 0.00;
> double sign = 1.00;
> double fractprt = 1.00;
> /* check for neg number */
> if ( *s == '-') {
> sign = -1.00;
> s++;
> }
>
> d=d*10.00 + ('0' - *s++);
> }
> if (*s == '.'){
> s++;
> d=d*10.00 + ('0' - *s++);
> fractprt *=10;
> }
> }
> return (sign * d / fractprt) ;
> }
>
> I get 36.03, not -36.03.

Note the sign of "'0' - *s++".

Why post the same thing three times?

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

mdh
Guest
Posts: n/a

 11-08-2007
On Nov 7, 6:28 pm, CBFalconer <(E-Mail Removed)> wrote:
> mdeh wrote:
>
> > I am trying to understand why I am not getting a negative value
> > back, using my version of atof

>
> > given the argument "-36.63"

>
> > double atof ( char *s){
> > double d = 0.00;
> > double sign = 1.00;
> > double fractprt = 1.00;
> > /* check for neg number */
> > if ( *s == '-') {
> > sign = -1.00;
> > s++;
> > }

>
> > d=d*10.00 + ('0' - *s++);
> > }
> > if (*s == '.'){
> > s++;
> > d=d*10.00 + ('0' - *s++);
> > fractprt *=10;
> > }
> > }
> > return (sign * d / fractprt) ;
> > }

>
> > I get 36.03, not -36.03.

>
> Note the sign of "'0' - *s++".
>
> Why post the same thing three times?
>

Just in case you missed the first 2

No Seriously, you must have missed my above post. Google was not
authentication, then kept asking as if nothing was happening. Well,
obviously, something was happening, as you can see by the number of
posts.