Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
AFKMud 2.2.2
Mar 3, 2019 5:35 pm
By Samson
Development
Nov 28, 2018 12:10 pm
By Keirath
First Immortal
Oct 12, 2018 2:02 pm
By GatewaySysop
Bug in do_climb( )
Jun 5, 2018 7:31 pm
By joeyfogas
question on overland code
May 31, 2018 12:03 pm
By joeyfogas
SmaugFUSS 1.9.3
Author: Various
Submitted by: Samson
AFKMud 2.2.2
Author: AFKMud Team
Submitted by: Samson
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Google

Members: 0
Guests: 13
Stats
Files
Topics
Posts
Members
Newest Member
483
3,743
19,401
655
RodrickMci
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds » Bugfix Lists » SWFOTE FUSS Bugfix List » [Bug] Planet structures use f...
Forum Rules | Mark all | Recent Posts

[Bug] Planet structures use float values, but no proper fread_float exists
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Mar 6, 2005 12:56 pm   Last edited May 6, 2005 2:16 am by Samson
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,647
JoinedJan 1, 2002

Bug: Planet structures use float values, but no proper fread_float exists.
Danger: Low - Inexact data
Found by: Greven
Fixed by: Greven/Samson

---

db.c

Near the top, in the includes, add:

#include <math.h>


Above the fread_number function, add:

/*
 * Read a float number from a file. Turn the result into a float value.
 */
float fread_float( FILE * fp )
{
   float number;
   bool sign, decimal;
   char c;
   double place = 0;

   do
   {
      if( feof( fp ) )
      {
         bug( "%s: EOF encountered on read.", __FUNCTION__ );
         if( fBootDb )
         {
            shutdown_mud( "Corrupt file somewhere." );
            exit( 1 );
         }
         return 0;
      }
      c = getc( fp );
   }
   while( isspace( c ) );

   number = 0;

   sign = FALSE;
   decimal = FALSE;

   if( c == '+' )
      c = getc( fp );
   else if( c == '-' )
   {
      sign = TRUE;
      c = getc( fp );
   }

   if( !isdigit( c ) )
   {
      bug( "%s: bad format. (%c)", __FUNCTION__, c );
      if( fBootDb )
         exit( 1 );
      return 0;
   }

   while( 1 )
   {
      if( c == '.' || isdigit( c ) )
      {
         if( c == '.' )
         {
            decimal = TRUE;
            c = getc( fp );
         }

         if( feof( fp ) )
         {
            bug( "%s: EOF encountered on read.", __FUNCTION__ );
            if( fBootDb )
               exit( 1 );
            return number;
         }
         if( !decimal )
            number = number * 10 + c - '0';
         else
         {
            place++;
            number += pow( 10, ( -1 * place ) ) * ( c - '0' );
         }
         c = getc( fp );
      }
      else
         break;
   }

   if( sign )
      number = 0 - number;

   if( c == '|' )
      number += fread_float( fp );
   else if( c != ' ' )
      ungetc( c, fp );

   return number;
}


mud.h

Locate:

int fread_number args( ( FILE * fp ) );


Below that, add:

float fread_float( FILE *fp );


planets.c, fread_planet

Locate:

         case 'P':
            KEY( "PopSupport", planet->pop_support, fread_number( fp ) );
            break;


Change to:

         case 'P':
            KEY( "PopSupport", planet->pop_support, fread_float( fp ) );
            break;


Data loaded into float values by fread_number will generally round to the nearest whole number. Not an all-together devastating thing to have happen, but it will throw any precision calculations right out the window. Such as planet population figures which need to be pretty exact. As an added benefit, you can now use fread_float in any other places you might need to load such data as well.
       
Pages:<< prev 1 next >>