Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
Bug in do_drag( )
Oct 8, 2017, 12:40 am
By GatewaySysop
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Beastmaster 6D sound files
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, DotBot, Yahoo!, Google

Members: 0
Guests: 9
Stats
Files
Topics
Posts
Members
Newest Member
476
3,704
19,231
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SmaugFUSS » how to display decimal points...
Forum Rules | Mark all | Recent Posts

how to display decimal points? - Solved
< Newer Topic :: Older Topic > code addition needed

Pages:<< prev 1 next >>
* #1 Jan 23, 2011, 7:12 pm
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

Okay, looking to display decimal points and to use them in general. I attempted to add Samson's fread_float function to test if it would do what I was looking to do, but it's missing information to properly install and test. There is no fread_double function (as I saw from a search through the forums). Not really sure how best to accomplish this goal. Any help or ideas would be appreciated.
       
Post is unread #2 Jan 24, 2011, 3:35 am   Last edited Jan 24, 2011, 3:39 am by Remcon
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,857
JoinedJul 26, 2005

Well this doesn't have to do with displaying, but this is the fread_double that is in LoP.
/* Read a double from a file. */
double fread_double( FILE *fp )
{
   double number, dcount, ndecim;
   bool sign, fdecimal;
   char c;

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

   number = 0.0;
   dcount = 0.1;

   sign = false;
   fdecimal = false;

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

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

   while( isdigit( c ) || c == '.' )
   {
      ndecim = 0.0;

      if( feof( fp ) )
      {
         bug( "%s: EOF encountered on read.", __FUNCTION__ );
         if( fBootDb )
            exit( 1 );
         return number;
      }
      if( c == '.' )
      {
         fdecimal = true;
         c = getc( fp );
         continue;
      }
      if( !fdecimal )
         number = number * 10 + c - '0';
      else
      {
         ndecim = ( ( c - '0' ) * dcount );
         number += ndecim;
         dcount = ( dcount * .1 ); /* Update dcount so its ready for next one */
      }
      c = getc( fp );
   }

   if( sign )
      number = 0 - number;

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

   return number;
}

Naturally this is for reading a double from a file.

When displaying a double I just normally go with a '%.f'.
       
Post is unread #3 Jan 24, 2011, 3:57 pm
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

well, was hoping that would fix my issue...but it hasn't. :sad:

soo...here's what I'm trying to accomplish:
    if(victim->race == RACE_DRAGON && !IS_NPC(victim) && victim->pcdata->dragonarmor > 0)
	{
	  ch_printf(victim, "Before reduced damage is %d\r\n", dam);
     dam -= ((victim->pcdata->dragonarmor/(victim->level * 15)) * .15 * dam);

// This is a temporary fix currently installed, though I'd prefer the above to work
//      dam -= (int)(dam / 6);
	  ch_printf(victim, "Reduced this much damage %d\r\n", test);
	}

dragonarmor is the amount of treasure the dragon has consumed, and returns a proper whole number value as expected
(victim->level *15) returns the proper value as a whole number
in order to try and figure out what's going on, I've done a number of different thing with test as my example
short test;
test = victim->pcdata->dragonarmor/6;

returns a whole number as expected
short test;
test = (victim->level * 15)/6;

returns a whole number as expected
short test;
test = dam/6;

returns a whole number as expected
short test;
test = victim->pcdata->dragonarmor/(victim->level * 15);

returns 0, except when victim->pcdata->dragonarmor and (victim->level * 15) equal the same, then it returns 1 -- I've tried %d which gives whole numbers and %f which is supposed to return decimals...returns 0 or 1, either way
short test;
test = victim->pcdata->dragonarmor/(victim->level * 15) * 100;

with the *100, it should return a whole value...it returns 0, unless, once again, dragonarmor and level*15 equal, then it returns 100.

Okay, so this is my trying to figure what the heck is going on. the first ch_printf shows me damage before this reduction as a whole number, the second one shows what the reduction is supposed to be after the reduction...I've attempted to simply (int) the test formulas, but they return the same values throughout. Basically, what I'm seeing here is, the code simply won't allow the use of two data fields in the manner I'm attempting to use them?

regardless of what %-code is used, one of the above responses are seen...well, not regardless.. %g returns 2.111E-311, or similar..basically 0.

Hopefully this information helps to portray what I'm attempting to do heh
       
Post is unread #4 Jan 24, 2011, 4:54 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,857
JoinedJul 26, 2005

Your using short which doesn't handle decimals. Change short test to double test.
       
Post is unread #5 Jan 24, 2011, 4:55 pm
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,857
JoinedJul 26, 2005

And what I posted isn't for that kind of thing it is used to read a double number from a file on loadup etc... Like in LoP I use a few doubles and that reads them from the files they are saved in.
       
Post is unread #6 Jan 24, 2011, 9:22 pm
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

Okay, I got it to work, finally. The problem with the whole equation was (victim->level * 15). Apparently, the code--or something--doesn't like mixing a field value with a straight number while in the denominator position. It 0's out the fraction and results in the rest of the equation being 0. I changed it to the following, and it works like I want it to now (in case anyone cares to know how it was fixed).
    if(victim->race == RACE_DRAGON && !IS_NPC(victim) && victim->pcdata->dragonarmor > 0)
      {
	 double multilevel;
 	 multilevel = 15;
	 dam -= (victim->pcdata->dragonarmor/((victim->level) * multilevel)) * .15 * dam;
      }

And thanks again for the fread_double, it definitely came in handy while debugging this to do what I wanted.

Down side is, fractions such as 1/10 still will not show via %f...as it 0's out.
       
Pages:<< prev 1 next >>