[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

BOUNCE rtl@rtlinux.org: Approval required: Non-member submissionfrom [Oliver.J.Enders@aero.org] (fwd)



>From owner-rtl Thu May 31 14:02:20 2001
Received: from mhultra.aero.org (mhultra.aero.org [130.221.88.102])
	by hq.fsmlabs.com (8.11.2/8.11.2) with ESMTP id f4VK2Js11091
	for <rtl@fsmlabs.com>; Thu, 31 May 2001 14:02:19 -0600
Received: from ladir01.aero.org by mhultra.aero.org with ESMTP for rtl@fsmlabs.com; Thu, 31 May 2001 12:55:33 -0700
Subject: Re: [rtl] atof not working
To: rtl@fsmlabs.com
From: Oliver.J.Enders@aero.org
Date: Thu, 31 May 2001 12:55:30 -0700
Message-Id: <OF296A50D9.F4C1E71A-ON88256A5D.006C82EB@aero.org>
X-MIMETrack: Serialize by Router on ladir01/AeroNet/Aerospace/US(Release 5.0.5 |September
 22, 2000) at 05/31/2001 12:55:33 PM
MIME-Version: 1.0
Content-type: text/plain; charset=us-ascii



See the archives on discussions of rtl_printf, scanf, atof, and similar
functions.  A number of people have ported portions of c library functions
and made them work under rtlinux.  One of the reasons the regular functions
don't work under rtlinux is internal usage of malloc and other dynamic
allocation that is not too helpful in real time.

Here are some functions I created that might be of some help to you.

// ---------------------------------------------------------------
// isdigit -- returns true if character is a digit
// ---------------------------------------------------------------
int isdigit(char c){ return 47< (int)c && (int)c < 58 ? 1 : 0;   }

// ----------------------------------------------------------------
// atoi  -- converts character string to an integer
// ----------------------------------------------------------------
int atoi(char *s) {
   int i, n, m, t, sign=1;

    // Search for a digit saving plus or minus sign if one is found.
    for(i=0; !isdigit(s[i]); i++) {
        if( s[i]==0 ) return 0;
        if( s[i]=='-' )  sign = -1;
        if( s[i]=='+' ) sign = 1;
    }

    // Count the digits
    for(t=0; isdigit(s[i]); i++, t++) {}

    // t -- total number of digits counted
   n=0;
    m=1;
    while (t--) {
       n = n + m * ( (int)s[--i]-48 );  // 48 = ascii code offset
      m = m * 10;
     }
    return sign*n;
}

// ----------------------------------------------------------------
// atof  -- converts fixed point character string to a double
// ----------------------------------------------------------------
double atof(char *s) {
    int i, j, n, m, t, sign=1;
    double leftside;

    // Search for a digit saving plus or minus sign if one is found.
    for(i=0; !isdigit(s[i]); i++) {
        if( s[i]==0 ) return 0;
        if( s[i]=='-' )  sign = -1;
        if( s[i]=='+' ) sign = 1;
   }

    // Count the digits
    for(t=0; isdigit(s[i]); i++, t++) {}

    // t -- total number of digits counted
    n=0;
    m=1;
    for (j=0;j<t;j++){
       n = n + m * ( (int)s[--i]-48 );  // 48 = ascii code offset
        m = m * 10;
    }
    leftside=(double)n;

     //Advance the index again ..
     i = i + t;

     //Now work on the right side of decimal point (if any)
     if ( s[i]=='.' && isdigit(s[i+1]) ) {
          i++;
          // Count the digits
     for(t=0; isdigit(s[i]); i++, t++) {}

     // t -- total number of digits counted
          n=0;
     m=1;
          while (t--) {
               n = n + m * ( (int)s[--i]-48 );  // 48 = ascii code offset
               m = m * 10;
     }
         // Glue together right side with left side ...
         return sign*(leftside+ (double)n/m);
     }
     else {
          //We are done
          return leftside;
     }
}


// ------------------------------------------------------------------
// skipfield -- counts characters in an integer or fixed point field.
// ------------------------------------------------------------------
int skipfield (char *s) {
     int i, j, n, m, t, sign=1;

     // Search for a digit saving plus or minus sign if one is found.
    for(i=0; !isdigit(s[i]); i++) {
          if( s[i]==0 ) return 0;
          if( s[i]=='-' )     sign = -1;
        if( s[i]=='+' ) sign = 1;
     }

     // Count the digits
    for(t=0; isdigit(s[i]); i++, t++) {}

    // t -- total number of digits counted
     n=0;
    m=1;
    for (j=0;j<t;j++){
       n = n + m * ( (int)s[--i]-48 );  // 48 = ascii code offset
        m = m * 10;
    }

     //Advance the index again ..
     i = i + t;

     //Now work on the right side of decimal point (if any)
     if ( s[i]=='.' && isdigit(s[i+1]) ) {
          i++;
          // Count the digits
     for(t=0; isdigit(s[i]); i++, t++) {}
         return i;
     }
     else {
         // no right side was encountered

          if (s[i]=='.') return i+1;
          return i;
     }
}




tfrasher@stellartec.com (Thomas Frasher)@fsmlabs.com on 05/30/2001 03:21:07
PM

Please respond to rtl@fsmlabs.com

Sent by:  owner-rtl@fsmlabs.com


To:   <rtl@rtlinux.org>
cc:
Subject:  [rtl] atof not working


     I'm trying to use atof to do.... what atof does actually.  I'm trying
this
in of all places a real-time (rtl2.2) module. The module cannot be
inserted,
when trying to insert, the message something like " undefined symbol
__strtod_internal".  If the same call is used in a program (exectuable< non
module) it works just fine.  Anybody have any ideas?

-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail majordomo@rtlinux.org OR
echo "unsubscribe rtl <Your_email>" | mail majordomo@rtlinux.org
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/