Changeset 27b799 in git for Singular/longrat0.cc


Ignore:
Timestamp:
May 27, 1998, 7:14:09 PM (26 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
311499b3c35b89d435a5b5b44c51e0ace5b13c6c
Parents:
b911ac5ddf660513a9fa06698ab8ac4553c1ef65
Message:
* hannes: removed non-gmp-parts


git-svn-id: file:///usr/local/Singular/svn/trunk@2005 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/longrat0.cc

    rb911ac r27b799  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: longrat0.cc,v 1.5 1997-06-04 19:45:21 obachman Exp $ */
     4/* $Id: longrat0.cc,v 1.6 1998-05-27 17:14:08 Singular Exp $ */
    55/*
    66* ABSTRACT -
     
    1515#include "febase.h"
    1616#include "longrat.h"
    17 
    18 #ifdef HAVE_GMP
    1917
    2018#define SR_HDL(A) ((long)(A))
     
    146144}
    147145
    148 #else
    149 #define NLLENGTH(a) ((int)(*(a)&0X7FFF))
    150 #define NUM_BASIS 10000
    151 #define NLISRAT(a)   ((a)->s)
    152 
    153 /*3
    154 * extracts a long integer from s, returns the rest
    155 */
    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 /*2
    178 * extracts the numberio a from s, returns the rest
    179 */
    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     else
    192       *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     else
    213     {
    214       *a = nlDiv(z, n);
    215       nlNormalize(*a);
    216     }
    217   }
    218   return s;
    219 }
    220 
    221 /*3
    222 * write long integer, assume n!=NULL
    223 */
    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   do
    241   {
    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 /*2
    257 * write a number
    258 */
    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 #endif
    280 
Note: See TracChangeset for help on using the changeset viewer.