Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Development
Nov 28, 2018, 10:10 am
By Keirath
First Immortal
Oct 12, 2018, 12:02 pm
By GatewaySysop
Bug in do_climb( )
Jun 5, 2018, 5:31 pm
By joeyfogas
question on overland code
May 31, 2018, 10:03 am
By joeyfogas
KaVir's Protocol Snip
May 15, 2018, 7:57 pm
By joeyfogas
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
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl

Members: 0
Guests: 22
Stats
Files
Topics
Posts
Members
Newest Member
481
3,740
19,397
632
ClarenceKe
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » 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, 10:56 am   Last edited May 6, 2005, 12:16 am by Samson
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,644
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 >>