ctldef.c File Reference

Miscellaneous implementation details and units. More...

#include <time.h>
#include "ctl/ctldef.h"

Include dependency graph for ctldef.c:

Go to the source code of this file.

Functions

bool _ctl_dummy_true (void)
 Dummy function call to force comparisons 'true' for invariant comparisons.
size_t int32_NumPlaces (int32 val)
 Calculate number of decimal places a signed 32 bit value will take in text output.
size_t uint32_NumPlaces (uint32 val)
 Calculate number of decimal places an unsigned 32 bit value will take in text output.
size_t int64_NumPlaces (int64 val)
 Calculate number of decimal places a signed 64 bit value will take in text output.
size_t uint64_NumPlaces (uint64 val)
 Calculate number of decimal places an unsigned 64 bit value will take in text output.
size_t uint32_XNumPlaces (uint32 val)
 Calculate number of hexadecimal places an unsigned 32 bit value will take in text output.
size_t uint64_XNumPlaces (uint64 val)
 Calculate number of hexadecimal places an unsigned 64 bit value will take in text output.


Detailed Description

Miscellaneous implementation details and units.

Author:
David Mace

Definition in file ctldef.c.


Function Documentation

size_t int32_NumPlaces ( int32  val  ) 

Calculate number of decimal places a signed 32 bit value will take in text output.

Parameters:
val Value we're counting decimal places on
Returns:
Size required to store this text

Definition at line 349 of file ctldef.c.

References uint32_NumPlaces().

00350 {
00351     size_t ret = 0;
00352     if( val < 0 )
00353     {
00354         val = -val;
00355         ret = 1;
00356         if( val < 0 )   /* int32 min */
00357             return 11;
00358     }
00359     return ret + uint32_NumPlaces( val );
00360 }

Here is the call graph for this function:

size_t int64_NumPlaces ( int64  val  ) 

Calculate number of decimal places a signed 64 bit value will take in text output.

Parameters:
val Value we're counting decimal places on
Returns:
Size required to store this text

Definition at line 406 of file ctldef.c.

References uint64_NumPlaces().

00407 {
00408     size_t ret = 0;
00409     if( val < 0 )
00410     {
00411         val = -val;
00412         ret = 1;
00413         if( val < 0 )
00414             return 20;
00415     }
00416     return ret + uint64_NumPlaces( val );
00417 }

Here is the call graph for this function:

size_t uint32_NumPlaces ( uint32  val  ) 

Calculate number of decimal places an unsigned 32 bit value will take in text output.

Parameters:
val Value we're counting decimal places on
Returns:
Size required to store this text

Definition at line 366 of file ctldef.c.

Referenced by int32_NumPlaces(), and uint64_NumPlaces().

00367 {
00368     if( val >= 100000u )
00369     {
00370         if( val >= 100000000u )
00371         {
00372             if( val >= 1000000000u )
00373             {
00374                 return 10;
00375             }
00376             return 9;
00377         }
00378         else if( val >= 1000000u )
00379         {
00380             if( val >= 10000000u )
00381                 return 8;
00382             return 7;
00383         }
00384         return 6;
00385     }
00386     else if( val >= 1000u )
00387     {
00388         if( val >= 10000u )
00389             return 5;
00390         return 4;
00391     }
00392     else if( val >= 10u )
00393     {
00394         if( val >= 100u )
00395             return 3;
00396         return 2;
00397     }
00398     return 1;
00399 }

size_t uint32_XNumPlaces ( uint32  val  ) 

Calculate number of hexadecimal places an unsigned 32 bit value will take in text output.

Parameters:
val Value we're counting decimal places on
Returns:
Size required to store this text

Definition at line 476 of file ctldef.c.

Referenced by uint64_XNumPlaces().

00477 {
00478     size_t ret = 1;
00479     if( val >= 0xffff0000 )
00480     {
00481         ret += 4;
00482         val >>= 16;
00483     }
00484     if( val >= 0xff00 )
00485     {
00486         ret += 2;
00487         val >>= 8;
00488     }
00489     if( val >= 0xf0 )
00490     {
00491         ret++;
00492     }
00493     return ret;
00494 }

size_t uint64_NumPlaces ( uint64  val  ) 

Calculate number of decimal places an unsigned 64 bit value will take in text output.

Parameters:
val Value we're counting decimal places on
Returns:
Size required to store this text

Definition at line 424 of file ctldef.c.

References billion, quadrillion, quintillion, trillion, and uint32_NumPlaces().

Referenced by int64_NumPlaces().

00425 {
00426     /*18,446,744,073,709,551,616 */
00427     if( val > uint64const(billion(1,000,000,000)) )
00428     {
00429         if( val >= uint64const(quadrillion(1,000,000,000,000,000)) )
00430         {
00431             if( val >= uint64const(quintillion(1,000,000,000,000,000,000)) )
00432             {
00433                 if( val >= uint64const(quintillion(10,000,000,000,000,000,000)) )
00434                     return 20;
00435                 /* else uint64const(quintillion(1,000,000,000,000,000,000)) */
00436                 return 19;
00437             }
00438             else /* if( val >= uint64const(quadrillion(1,000,000,000,000,000)) ) */
00439             {
00440                 if( val >= uint64const(quadrillion(100,000,000,000,000,000)) )
00441                     return 18;
00442                 if( val >= uint64const(quadrillion(10,000,000,000,000,000)) )
00443                     return 17;
00444                 /* else uint64const(quadrillion(1,000,000,000,000,000)) */
00445                 return 16;
00446             }
00447         }
00448         else if( val >= uint64const(trillion(1,000,000,000,000)) )
00449         {
00450             if( val >= uint64const(trillion(100,000,000,000,000)) )
00451                 return 15;
00452             if( val >= uint64const(trillion(10,000,000,000,000)) )
00453                 return 14;
00454             /* else uint64const(trillion(1,000,000,000,000)) */
00455             return 13;
00456         }
00457         else /* if( val >= uint64const(billion(1,000,000,000)) ) */
00458         {
00459             if( val >= uint64const(billion(100,000,000,000)) )
00460                 return 12;
00461             if( val >= uint64const(billion(10,000,000,000)) )
00462                 return 11;
00463             /* else uint64const(billion(1,000,000,000)) */
00464             return 10;
00465         }
00466     }
00467     return uint32_NumPlaces( (uint32)val );
00468 
00469 }

Here is the call graph for this function:

size_t uint64_XNumPlaces ( uint64  val  ) 

Calculate number of hexadecimal places an unsigned 64 bit value will take in text output.

Parameters:
val Value we're counting decimal places on
Returns:
Size required to store this text

Definition at line 500 of file ctldef.c.

References uint32_XNumPlaces().

00501 {
00502     if( val > 0xffffffff )
00503     {
00504         val >>= 32;
00505         return 32+uint32_XNumPlaces( (uint32)val );
00506     }
00507     return uint32_XNumPlaces( (uint32)val );
00508 }

Here is the call graph for this function:


Generated on Fri Jan 2 15:28:35 2009 for Squat by  doxygen 1.5.6