source: git/kernel/misc.cc @ 06662e

spielwiese
Last change on this file since 06662e was 9a310a, checked in by Hans Schoenemann <hannes@…>, 14 years ago
omSingularConfig.h removed git-svn-id: file:///usr/local/Singular/svn/trunk@12758 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT:
6*/
7
8#include <string.h>
9#include <unistd.h>
10#include <stdio.h>
11#include <stddef.h>
12#include <stdlib.h>
13#include <time.h>
14
15#include "mod2.h"
16#include <mylimits.h>
17#include "omalloc.h"
18#include "structs.h"
19#include "options.h"
20#include "febase.h"
21//#include "cntrlc.h"
22#include "kstd1.h"
23#include "timer.h"
24#include "intvec.h"
25#include "ring.h"
26#include "p_Procs.h"
27#include "kversion.h"
28
29#define SI_DONT_HAVE_GLOBAL_VARS
30
31//#ifdef HAVE_LIBPARSER
32//#  include "libparse.h"
33//#endif /* HAVE_LIBPARSER */
34
35#ifdef HAVE_FACTORY
36#include <factory.h>
37/* libfac version strings */
38  extern const char * libfac_version;
39  extern const char * libfac_date;
40#endif
41
42#include <si_gmp.h>
43#ifdef HAVE_MPSR
44#include <MP_Config.h>
45#endif
46
47/* init bins from structs.h */
48
49omBin char_ptr_bin = omGetSpecBin(sizeof(char_ptr));
50
51/*0 implementation*/
52
53/*2
54* the global exit routine of Singular
55*/
56#ifdef HAVE_MPSR
57void (*MP_Exit_Env_Ptr)()=NULL;
58#endif
59extern "C" {
60
61void m2_end(int i)
62{
63  fe_reset_input_mode();
64  #ifdef PAGE_TEST
65  mmEndStat();
66  #endif
67  #ifdef HAVE_TCL
68  if (tclmode)
69  {
70    PrintTCL('Q',0,NULL);
71  }
72  #endif
73  fe_reset_input_mode();
74  if (i<=0)
75  {
76    #ifdef HAVE_TCL
77    if (!tclmode)
78    #endif
79      if (TEST_V_QUIET)
80      {
81        if (i==0)
82          printf("Auf Wiedersehen.\n");
83        else
84          printf("\n$Bye.\n");
85      }
86    //#ifdef sun
87    //  #ifndef __svr4__
88    //    _cleanup();
89    //    _exit(0);
90    //  #endif
91    //#endif
92    exit(0);
93  }
94  else
95  {
96    #ifdef HAVE_TCL
97    if (!tclmode)
98    #endif
99      printf("\nhalt %d\n",i);
100  }
101  #ifdef HAVE_MPSR
102  if (MP_Exit_Env_Ptr!=NULL) (*MP_Exit_Env_Ptr)();
103  #endif
104  exit(i);
105}
106}
107
108/*2
109* the renice routine for very large jobs
110* works only on unix machines,
111* testet on : linux, HP 9.0
112*
113*#include <sys/times.h>
114*#include <sys/resource.h>
115*extern "C" int setpriority(int,int,int);
116*void very_nice()
117*{
118*#ifndef NO_SETPRIORITY
119*  setpriority(PRIO_PROCESS,0,19);
120*#endif
121*  sleep(10);
122*}
123*/
124
125/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
126#ifdef buildin_rand
127/*
128 *
129 *  A prime modulus multiplicative linear congruential
130 *  generator (PMMLCG), or "Lehmer generator".
131 *  Implementation directly derived from the article:
132 *
133 *        S. K. Park and K. W. Miller
134 *        Random Number Generators: Good Ones are Hard to Find
135 *        CACM vol 31, #10. Oct. 1988. pp 1192-1201.
136 *
137 *  Using the following multiplier and modulus, we obtain a
138 *  generator which:
139 *
140 *        1)  Has a full period: 1 to 2^31 - 2.
141 *        2)  Is testably "random" (see the article).
142 *        3)  Has a known implementation by E. L. Schrage.
143 */
144
145
146#define  A        16807        /*  A "good" multiplier          */
147#define  M   2147483647        /*  Modulus: 2^31 - 1          */
148#define  Q       127773        /*  M / A                  */
149#define  R         2836        /*  M % A                  */
150
151
152int siSeed = 1;
153
154
155int siRand()
156{
157  siSeed = A * (siSeed % Q) - R * (siSeed / Q);
158
159  if ( siSeed < 0 )
160    siSeed += M;
161
162  return( siSeed );
163}
164#endif
165
Note: See TracBrowser for help on using the repository browser.