source: git/kernel/misc.cc @ 35aab3

spielwiese
Last change on this file since 35aab3 was 35aab3, checked in by Hans Schönemann <hannes@…>, 21 years ago
This commit was generated by cvs2svn to compensate for changes in r6879, which included commits to RCS files with non-trunk default branches. git-svn-id: file:///usr/local/Singular/svn/trunk@6880 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.0 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 "version.h"
28
29#include "static.h"
30#ifdef HAVE_STATIC
31#undef HAVE_DYN_RL
32#endif
33
34#define SI_DONT_HAVE_GLOBAL_VARS
35
36//#ifdef HAVE_LIBPARSER
37//#  include "libparse.h"
38//#endif /* HAVE_LIBPARSER */
39
40#ifdef HAVE_FACTORY
41#include <factory.h>
42#endif
43
44/* version strings */
45#ifdef HAVE_LIBFAC_P
46  extern const char * libfac_version;
47  extern const char * libfac_date;
48#endif
49extern "C" {
50#include <gmp.h>
51}
52#ifdef HAVE_MPSR
53#include <MP_Config.h>
54#endif
55
56/* init bins from structs.h */
57
58omBin MP_INT_bin = omGetSpecBin(sizeof(MP_INT));
59omBin char_ptr_bin = omGetSpecBin(sizeof(char_ptr));
60omBin ideal_bin = omGetSpecBin(sizeof(ideal));
61omBin int_bin = omGetSpecBin(sizeof(int));
62omBin poly_bin = omGetSpecBin(sizeof(poly));
63omBin void_ptr_bin = omGetSpecBin(sizeof(void_ptr));
64omBin indlist_bin = omGetSpecBin(sizeof(indlist));
65omBin naIdeal_bin = omGetSpecBin(sizeof(naIdeal));
66omBin snaIdeal_bin = omGetSpecBin(sizeof(snaIdeal));
67omBin sm_prec_bin = omGetSpecBin(sizeof(sm_prec));
68omBin smprec_bin = omGetSpecBin(sizeof(smprec));
69omBin sip_sideal_bin = omGetSpecBin(sizeof(sip_sideal));
70omBin sip_smap_bin = omGetSpecBin(sizeof(sip_smap));
71omBin sip_sring_bin = omGetSpecBin(sizeof(sip_sring));
72omBin ip_sideal_bin = omGetSpecBin(sizeof(ip_sideal));
73omBin ip_smap_bin = omGetSpecBin(sizeof(ip_smap));
74omBin ip_sring_bin = omGetSpecBin(sizeof(ip_sring));
75
76/*0 implementation*/
77
78/*2
79* the global exit routine of Singular
80*/
81extern "C" {
82void m2_end(short i)
83{
84  fe_reset_input_mode();
85  #ifdef PAGE_TEST
86  mmEndStat();
87  #endif
88  #ifdef HAVE_TCL
89  if (tclmode)
90  {
91    PrintTCL('Q',0,NULL);
92  }
93  #endif
94  fe_reset_input_mode();
95  if (i<=0)
96  {
97    #ifdef HAVE_TCL
98    if (!tclmode)
99    #endif
100      if (BVERBOSE(0))
101      {
102        if (i==0)
103          printf("Auf Wiedersehen.\n");
104        else
105          printf("\n$Bye.\n");
106      }
107    #ifdef sun
108      #ifndef __svr4__
109        _cleanup();
110        _exit(0);
111      #endif
112    #endif
113    exit(0);
114  }
115  else
116  {
117    #ifdef HAVE_TCL
118    if (!tclmode)
119    #endif
120      printf("\nhalt %d\n",i);
121  }
122  exit(i);
123}
124}
125
126/*2
127* the renice routine for very large jobs
128* works only on unix machines,
129* testet on : linux, HP 9.0
130*
131*#ifndef MSDOS
132*#ifndef macintosh
133*#include <sys/times.h>
134*#include <sys/resource.h>
135*extern "C" int setpriority(int,int,int);
136*void very_nice()
137*{
138*#ifndef NO_SETPRIORITY
139*  setpriority(PRIO_PROCESS,0,19);
140*#endif
141*  sleep(10);
142*}
143*#else
144*void very_nice(){}
145*#endif
146*#else
147*void very_nice(){}
148*#endif
149*/
150
151/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
152#ifdef buildin_rand
153/*
154 *
155 *  A prime modulus multiplicative linear congruential
156 *  generator (PMMLCG), or "Lehmer generator".
157 *  Implementation directly derived from the article:
158 *
159 *        S. K. Park and K. W. Miller
160 *        Random Number Generators: Good Ones are Hard to Find
161 *        CACM vol 31, #10. Oct. 1988. pp 1192-1201.
162 *
163 *  Using the following multiplier and modulus, we obtain a
164 *  generator which:
165 *
166 *        1)  Has a full period: 1 to 2^31 - 2.
167 *        2)  Is testably "random" (see the article).
168 *        3)  Has a known implementation by E. L. Schrage.
169 */
170
171
172#define  A        16807L        /*  A "good" multiplier          */
173#define  M   2147483647L        /*  Modulus: 2^31 - 1          */
174#define  Q       127773L        /*  M / A                  */
175#define  R         2836L        /*  M % A                  */
176
177
178int siSeed = 1L;
179
180
181int siRand()
182{
183  siSeed = A * (siSeed % Q) - R * (siSeed / Q);
184
185  if ( siSeed < 0 )
186    siSeed += M;
187
188  return( siSeed );
189}
190#endif
191
Note: See TracBrowser for help on using the repository browser.