source: git/kernel/misc.cc @ 6c4db17

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