source: git/kernel/misc.cc @ a7efc97

fieker-DuValspielwiese
Last change on this file since a7efc97 was 2798e9c, checked in by Hans Schönemann <hannes@…>, 14 years ago
git-svn-id: file:///usr/local/Singular/svn/trunk@12411 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 3.5 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 "febase.h"
20//#include "cntrlc.h"
21#include "kstd1.h"
22#include "timer.h"
23#include "intvec.h"
24#include "ring.h"
25#include "omSingularConfig.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));
50omBin ideal_bin = omGetSpecBin(sizeof(ideal));
51omBin indlist_bin = omGetSpecBin(sizeof(indlist));
52omBin naIdeal_bin = omGetSpecBin(sizeof(naIdeal));
53omBin snaIdeal_bin = omGetSpecBin(sizeof(snaIdeal));
54omBin smprec_bin = omGetSpecBin(sizeof(smprec));
55omBin sip_sideal_bin = omGetSpecBin(sizeof(sip_sideal));
56omBin sip_smap_bin = omGetSpecBin(sizeof(sip_smap));
57omBin sip_sring_bin = omGetSpecBin(sizeof(sip_sring));
58
59/*0 implementation*/
60
61/*2
62* the global exit routine of Singular
63*/
64#ifdef HAVE_MPSR
65void (*MP_Exit_Env_Ptr)()=NULL;
66#endif
67extern "C" {
68
69void m2_end(int i)
70{
71  fe_reset_input_mode();
72  #ifdef PAGE_TEST
73  mmEndStat();
74  #endif
75  #ifdef HAVE_TCL
76  if (tclmode)
77  {
78    PrintTCL('Q',0,NULL);
79  }
80  #endif
81  fe_reset_input_mode();
82  if (i<=0)
83  {
84    #ifdef HAVE_TCL
85    if (!tclmode)
86    #endif
87      if (BVERBOSE(0))
88      {
89        if (i==0)
90          printf("Auf Wiedersehen.\n");
91        else
92          printf("\n$Bye.\n");
93      }
94    //#ifdef sun
95    //  #ifndef __svr4__
96    //    _cleanup();
97    //    _exit(0);
98    //  #endif
99    //#endif
100    exit(0);
101  }
102  else
103  {
104    #ifdef HAVE_TCL
105    if (!tclmode)
106    #endif
107      printf("\nhalt %d\n",i);
108  }
109  #ifdef HAVE_MPSR
110  if (MP_Exit_Env_Ptr!=NULL) (*MP_Exit_Env_Ptr)();
111  #endif
112  exit(i);
113}
114}
115
116/*2
117* the renice routine for very large jobs
118* works only on unix machines,
119* testet on : linux, HP 9.0
120*
121*#include <sys/times.h>
122*#include <sys/resource.h>
123*extern "C" int setpriority(int,int,int);
124*void very_nice()
125*{
126*#ifndef NO_SETPRIORITY
127*  setpriority(PRIO_PROCESS,0,19);
128*#endif
129*  sleep(10);
130*}
131*/
132
133/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
134#ifdef buildin_rand
135/*
136 *
137 *  A prime modulus multiplicative linear congruential
138 *  generator (PMMLCG), or "Lehmer generator".
139 *  Implementation directly derived from the article:
140 *
141 *        S. K. Park and K. W. Miller
142 *        Random Number Generators: Good Ones are Hard to Find
143 *        CACM vol 31, #10. Oct. 1988. pp 1192-1201.
144 *
145 *  Using the following multiplier and modulus, we obtain a
146 *  generator which:
147 *
148 *        1)  Has a full period: 1 to 2^31 - 2.
149 *        2)  Is testably "random" (see the article).
150 *        3)  Has a known implementation by E. L. Schrage.
151 */
152
153
154#define  A        16807        /*  A "good" multiplier          */
155#define  M   2147483647        /*  Modulus: 2^31 - 1          */
156#define  Q       127773        /*  M / A                  */
157#define  R         2836        /*  M % A                  */
158
159
160int siSeed = 1;
161
162
163int siRand()
164{
165  siSeed = A * (siSeed % Q) - R * (siSeed / Q);
166
167  if ( siSeed < 0 )
168    siSeed += M;
169
170  return( siSeed );
171}
172#endif
173
Note: See TracBrowser for help on using the repository browser.