File: compute_machine_constants.c

package info (click to toggle)
unuran 1.11.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 21,344 kB
  • sloc: ansic: 204,607; sh: 4,783; perl: 3,160; makefile: 839; cpp: 24
file content (111 lines) | stat: -rw-r--r-- 5,784 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*****************************************************************************
 *                                                                           *
 *          unuran -- Universal Non-Uniform Random number generator          *
 *                                                                           *
 *****************************************************************************
 *                                                                           *
 *   FILE:      compute_machine_constants.c                                  *
 *                                                                           *
 *   Compute some machine constants and print to stdout                      *
 *                                                                           *
 *****************************************************************************
 *                                                                           *
 *   Copyright (c) 2000-2006 Wolfgang Hoermann and Josef Leydold             *
 *   Department of Statistics and Mathematics, WU Wien, Austria              *
 *                                                                           *
 *   This program is free software; you can redistribute it and/or modify    *
 *   it under the terms of the GNU General Public License as published by    *
 *   the Free Software Foundation; either version 2 of the License, or       *
 *   (at your option) any later version.                                     *
 *                                                                           *
 *   This program is distributed in the hope that it will be useful,         *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with this program; if not, write to the                           *
 *   Free Software Foundation, Inc.,                                         *
 *   59 Temple Place, Suite 330, Boston, MA 02111-1307, USA                  *
 *                                                                           *
 *****************************************************************************/

/*---------------------------------------------------------------------------*/

#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

/*---------------------------------------------------------------------------*/

/** TODO:
#define MAXLGM 2.556348e305
**/

/*---------------------------------------------------------------------------*/

int main(void)
{

  printf("/** File automatically created by scripts/compute_machine_constants         **/\n\n");

  printf("/*****************************************************************************\n");
  printf(" *                                                                           *\n");
  printf(" *          unuran -- Universal Non-Uniform Random number generator          *\n");
  printf(" *                                                                           *\n");
  printf(" *****************************************************************************/\n");

  printf("\n");

  printf("/*---------------------------------------------------------------------------*/\n");
  printf("#ifndef UNUR_FP_CONST_SOURCE_H_SEEN\n");
  printf("#define UNUR_FP_CONST_SOURCE_H_SEEN\n");
  printf("/*---------------------------------------------------------------------------*/\n\n");


  /* Epsilon for comparision of two doubles:                                   */
  /* Two doubles are considered equal if there relative difference is          */
  /* less than UNUR_EPSILON (see file `./methods/source_fp.h' for details).    */
  /* Use 100 times DBL_EPSILON.                                                */

  printf("/* maximal relative error when testing equality of two doubles */\n");
  printf("#define UNUR_EPSILON  %.30g\n\n", 100.*DBL_EPSILON);


  /* Square root of machine epsilon. It is used to compare two doubles         */
  /* when round-off errors have to be considered                               */
  /* (see file `./methods/source_fp.h' for details).                           */

  printf("/* square root of DBL_EPSILON */\n");  
  printf("#define UNUR_SQRT_DBL_EPSILON   %.30g\n\n", sqrt(DBL_EPSILON));

  /* Log of machine epsilon.                                                   */
  /* Negative of least number x such that exp(x)-1. == exp(x)                  */

  printf("/* log of DBL_EPSILON */\n");  
  printf("#define UNUR_LOG_DBL_EPSILON   %.30g\n\n", log(DBL_EPSILON));

  /* Constants used by CEPHES functions */

  printf("/* the machine roundoff error */\n");  
  printf("#define MACHEP  %.30g\n\n", DBL_EPSILON/2.);

  printf("/* largest argument for exp() */\n");
  printf("#define MAXLOG  %.30g\n\n", log(DBL_MAX)); 

  printf("/* smallest argument for exp() without underflow */\n");
  printf("#define MINLOG  %.30g\n\n", log(DBL_MIN)); 

  printf("/* the maximal number that pow(x,x-0.5) has no overflow */\n");
  printf("/* we use a (very) conservative portable bound          */\n");
  printf("#define MAXSTIR  %.30g\n\n", log(DBL_MAX) / log(log(DBL_MAX)) );

  printf("/*---------------------------------------------------------------------------*/\n");
  printf("#endif  /* UNUR_FP_CONST_SOURCE_H_SEEN */\n");
  printf("/*---------------------------------------------------------------------------*/\n");

  exit (0);
}

/*---------------------------------------------------------------------------*/