MusicKit  0.0.0
noDVal.h
00001 /*
00002   $Id$
00003   Defined In: The MusicKit
00004 
00005   Description:
00006     This is used by the Music Kit to signal "no value" from functions and
00007     methods that return double. The value MK_NODVAL is a particular "NaN"
00008     ("not a number"). You cannot test its value directly.
00009     Instead, use MKIsNoDVal().
00010 
00011     Example:
00012 
00013          double myFunction(int arg)
00014          {
00015                  if (arg == 2)
00016                          return MK_NODVAL;
00017                  else return (double) arg * 2;
00018          }
00019 
00020          main()
00021          {
00022                  double d = myFunction(2);
00023                  if (MKIsNoDVal(d))
00024                          printf("Illegal value.\n");
00025          }
00026 
00027   Original Author: David Jaffe
00028 
00029   Copyright (c) 1988-1992, NeXT Computer, Inc.
00030   Portions Copyright (c) 1994 NeXT Computer, Inc. and reproduced under license from NeXT
00031   Portions Copyright (c) 1994 Stanford University
00032   Portions Copyright (c) 1999-2005 The MusicKit Project
00033 */
00034 #ifndef __MK_noDVal_H___
00035 #define __MK_noDVal_H___
00036   
00037 #ifndef _MK_NANHI
00038 #define _MK_NANHI 0x7ff80000 /* High bits of a particular non-signaling NaN */
00039 #define _MK_NANLO 0x0        /* Low bits of a particular non-signaling NaN */
00040 #endif
00041 
00042 #ifndef MK_NODVAL
00043 
00068 inline double MKGetNoDVal(void)
00069 {
00070     union {double d; int i[2];} u;
00071     u.i[0] = _MK_NANHI;
00072     u.i[1] = _MK_NANLO;
00073     return u.d;
00074 }
00075 
00091 inline int MKIsNoDVal(double value)
00092 {
00093     union {double d; int i[2];} u;
00094     u.d = value;
00095     return (u.i[0] == _MK_NANHI); /* Don't bother to check low bits. */
00096 }
00097 
00108 #define MK_NODVAL MKGetNoDVal()     /* For convenience */
00109 
00110 #endif
00111 
00112 #endif