source: git/kernel/misc.cc @ 3c38b38

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