Changeset 27b799 in git for Singular/longrat0.cc
- Timestamp:
- May 27, 1998, 7:14:09 PM (26 years ago)
- Branches:
- (u'spielwiese', 'ec94ef7a30b928574c0c3daf41f6804dff5f6b69')
- Children:
- 311499b3c35b89d435a5b5b44c51e0ace5b13c6c
- Parents:
- b911ac5ddf660513a9fa06698ab8ac4553c1ef65
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/longrat0.cc
rb911ac r27b799 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: longrat0.cc,v 1. 5 1997-06-04 19:45:21 obachmanExp $ */4 /* $Id: longrat0.cc,v 1.6 1998-05-27 17:14:08 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT - … … 15 15 #include "febase.h" 16 16 #include "longrat.h" 17 18 #ifdef HAVE_GMP19 17 20 18 #define SR_HDL(A) ((long)(A)) … … 146 144 } 147 145 148 #else149 #define NLLENGTH(a) ((int)(*(a)&0X7FFF))150 #define NUM_BASIS 10000151 #define NLISRAT(a) ((a)->s)152 153 /*3154 * extracts a long integer from s, returns the rest155 */156 static char * nlEatLong(char *s, number *i)157 {158 number j, k, ten, n;159 j = nlInit(0);160 ten = nlInit(10);161 while (*s >= '0' && *s <= '9')162 {163 k = nlMult(j, ten);164 nlDelete(&j);165 j = nlInit((int)*s-(int)'0');166 s++;167 n = nlAdd(j, k);168 nlDelete(&j);169 nlDelete(&k);170 j = n;171 }172 nlDelete(&ten);173 *i = j;174 return s;175 }176 177 /*2178 * extracts the numberio a from s, returns the rest179 */180 char * nlRead (char *s, number *a)181 {182 number z, n;183 BOOLEAN neg = (*s == '-');184 185 if (*s == '+' || *s == '-')186 s++;187 if (*s<'0' || *s>'9')188 {189 if (neg)190 *a = nlInit(-1);191 else192 *a = nlInit(1);193 return s;194 }195 s = nlEatLong(s, &z);196 if (neg)197 nlNeg(z);198 *a = z;199 if (*s == '/')200 {201 s++;202 s = nlEatLong(s, &n);203 if (nlIsZero(n))204 {205 WerrorS("Zero Denominator");206 nlDelete(&n);207 nlDelete(a);208 return s;209 }210 if (nlIsOne(n))211 nlDelete(&n);212 else213 {214 *a = nlDiv(z, n);215 nlNormalize(*a);216 }217 }218 return s;219 }220 221 /*3222 * write long integer, assume n!=NULL223 */224 static void nlWriteLong(lint n)225 {226 char save;227 char *lonstr, *str1;228 int i, k, j;229 lint a;230 int16 al, w;231 al = NLLENGTH(n);232 k = al+1;233 i = k*sizeof(int16);234 a = (lint)Alloc(i);235 memcpy(a, n, i);236 j = k*5*sizeof(char);237 lonstr = (char *)Alloc(j);238 str1 = lonstr+(k*5-1);239 *str1 = '\0';240 do241 {242 nlDivMod(a, al, NUM_BASIS, &w);243 save = *str1;244 str1 -= 4;245 sprintf(str1, "%04u", w);246 str1[4] = save;247 if (a[al]==0)248 al--;249 } while (al!=0);250 Free((ADDRESS)a,i);251 while (*str1 == '0') str1++;252 StringAppend(str1);253 Free((ADDRESS)lonstr, j);254 }255 256 /*2257 * write a number258 */259 void nlWrite (number &a)260 {261 if (nlIsZero(a))262 {263 StringAppend("0");264 return;265 }266 if (!nlGreaterZero(a))267 {268 StringAppend("-");269 }270 if (a->s<0)271 nlNormalize(a);272 nlWriteLong(a->z);273 if (NLISRAT(a))274 {275 StringAppend("/");276 nlWriteLong(a->n);277 }278 }279 #endif280
Note: See TracChangeset
for help on using the changeset viewer.