source: git/kernel/misc.cc @ 223fd4

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