Fraction.st
changeset 8913 b9498d27a554
parent 8629 07ece572135f
child 10486 ecab71364dab
equal deleted inserted replaced
8912:3d1947a79cf3 8913:b9498d27a554
    87 %{  /* NOCONTEXT */
    87 %{  /* NOCONTEXT */
    88 
    88 
    89     /* this check allows subclassing .. */
    89     /* this check allows subclassing .. */
    90     if (self == Fraction) {
    90     if (self == Fraction) {
    91         if (__bothSmallInteger(num, den)) {
    91         if (__bothSmallInteger(num, den)) {
    92             if (den != __MKSMALLINT(0)) {
    92             if (den != __mkSmallInteger(0)) {
    93                 if (__CanDoQuickAlignedNew(sizeof(struct __Fraction))) {    /* OBJECT ALLOCATION */
    93                 if (__CanDoQuickAlignedNew(sizeof(struct __Fraction))) {    /* OBJECT ALLOCATION */
    94                     OBJ newFraction;
    94                     OBJ newFraction;
    95                     int spc;
    95                     int spc;
    96                     INT iDen;
    96                     INT iDen;
    97 
    97 
    99                     __InstPtr(newFraction)->o_class = self;
    99                     __InstPtr(newFraction)->o_class = self;
   100                     __qSTORE(newFraction, self);
   100                     __qSTORE(newFraction, self);
   101                     iDen = __intVal(den);
   101                     iDen = __intVal(den);
   102                     if (iDen != 0) {
   102                     if (iDen != 0) {
   103                         if (iDen < 0) {
   103                         if (iDen < 0) {
   104                             __FractionInstPtr(newFraction)->f_numerator = __MKSMALLINT(- __intVal(num));
   104                             __FractionInstPtr(newFraction)->f_numerator = __mkSmallInteger(- __intVal(num));
   105                             __FractionInstPtr(newFraction)->f_denominator = __MKSMALLINT(- iDen);
   105                             __FractionInstPtr(newFraction)->f_denominator = __mkSmallInteger(- iDen);
   106                         } else {
   106                         } else {
   107                             __FractionInstPtr(newFraction)->f_numerator = num;
   107                             __FractionInstPtr(newFraction)->f_numerator = num;
   108                             __FractionInstPtr(newFraction)->f_denominator = den;
   108                             __FractionInstPtr(newFraction)->f_denominator = den;
   109                         }
   109                         }
   110                         if (num == __MKSMALLINT(1)) {
   110                         if (num == __mkSmallInteger(1)) {
   111                             /* no need to reduce */
   111                             /* no need to reduce */
   112                             RETURN ( newFraction );
   112                             RETURN ( newFraction );
   113                         }
   113                         }
   114                     }
   114                     }
   115                 }
   115                 }
  1096 ! !
  1096 ! !
  1097 
  1097 
  1098 !Fraction class methodsFor:'documentation'!
  1098 !Fraction class methodsFor:'documentation'!
  1099 
  1099 
  1100 version
  1100 version
  1101     ^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.71 2004-11-10 10:40:41 penk Exp $'
  1101     ^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.72 2005-07-08 17:15:01 cg Exp $'
  1102 ! !
  1102 ! !
  1103 
  1103 
  1104 Fraction initialize!
  1104 Fraction initialize!