Skip to content

Commit

Permalink
Make the dUnitXX() functions safe to call with unit=NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
jedbrown committed Jun 17, 2011
1 parent 3d299e6 commit 12ec27f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/util/dunits.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ struct _n_dUnit {
dReal expon[dUNITS_MAX];
};

static const char nounit[] = "nounit";
const char *dUnitQuantityName(dUnit u)
{return u->quantity;}
{return u ? u->quantity : nounit;}
const char *dUnitName(dUnit u)
{return u->longname;}
{return u ? u->longname : nounit;}
const char *dUnitShortName(dUnit u)
{return u->shortname;}
{return u ? u->shortname : nounit;}
const char *dUnitSIName(dUnit u)
{return u->siname;}
{return u ? u->siname : nounit;}
dScalar dUnitDimensionalize(dUnit u,dScalar x)
{return x * u->toCommon;}
{return u ? x * u->toCommon : x;}
dScalar dUnitNonDimensionalize(dUnit u,dScalar x)
{return x / u->toCommon;}
{return u ? x / u->toCommon : x;}
dScalar dUnitDimensionalizeSI(dUnit u,dScalar x)
{return x * u->toSI;}
{return u ? x * u->toSI : x;}
dScalar dUnitNonDimensionalizeSI(dUnit u,dScalar x)
{return x / u->toSI;}
{return u ? x / u->toSI : x;}

const char *const dUnitsBaseTypes[] = {"LENGTH","MASS","TIME","TEMPERATURE","dUnitsBaseType","dUNITS_",0};
const char *const dUnitsBaseNamesSI[] = {"meter","kilogram","second","Kelvin"};
Expand Down

0 comments on commit 12ec27f

Please sign in to comment.