Changeset 1dd938 in git


Ignore:
Timestamp:
Apr 17, 2015, 10:51:08 AM (8 years ago)
Author:
Yue Ren <ren@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
7cb9b47e0c889244f467795deb33c7c8156369b4
Parents:
7203f75e9a4e317e9e009db8a853ed8c0e6be635
Message:
chg: min and max now take more than 2 inputs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/standard.lib

    r7203f7 r1dd938  
    1717 par2varRing([i])       create a ring making pars to vars, together with i
    1818 datetime()             return date and time as a string
    19  max(i,j)               maximum of i and j
    20  min(i,j)               minimum of i and j
     19 max(i_1,...,i_k)       maximum of i_1, ..., i_k
     20 min(i_1,...,i_k)       minimum of i_1, ..., i_k
    2121
    2222";
     
    21852185
    21862186///////////////////////////////////////////////////////////////////////////////
    2187 proc max(def i,def j)
    2188 "SYNTAX: max (i, j)
    2189 TYPE:    same as type of i resp. j
    2190 PURPOSE: returns the maximum for any 2 arguments of a type
     2187proc max(def i,list #)
     2188"SYNTAX: max (i_1, ..., i_k)
     2189TYPE:    same as type of i_1, ..., i_k resp.
     2190PURPOSE: returns the maximum for any arguments of a type
    21912191         for which '>' is defined
    21922192SEE ALSO: min
    21932193EXAMPLE: example max; shows an example"
    21942194{
    2195   if(i>j){return(i);}
    2196   return(j);
     2195  def maximum = i;
     2196  for (int j=1; j<=size(#); j++)
     2197  {
     2198    if(#[j]>maximum)
     2199    {
     2200      maximum = #[j];
     2201    }
     2202  }
     2203  return(maximum);
    21972204}
    21982205example
     
    22022209}
    22032210///////////////////////////////////////////////////////////////////////////////
    2204 proc min(def i,def j)
    2205 "SYNTAX: min (i, j)
    2206 TYPE:    same as type of i resp. j
    2207 PURPOSE: returns the minimum for any 2 arguments of a type
     2211proc min(def i,list #)
     2212"SYNTAX: min (i_1, ..., i_k)
     2213TYPE:    same as type of i_1, ..., i_k resp.
     2214PURPOSE: returns the minimum for any arguments of a type
    22082215         for which '>' is defined
    22092216SEE ALSO: max
    22102217EXAMPLE: example min; shows an example"
    22112218{
    2212   if(i>j){return(j);}
    2213   return(i);
     2219  def minimum = i;
     2220  for (int j=1; j<=size(#); j++)
     2221  {
     2222    if(#[j]<minimum)
     2223    {
     2224      minimum = #[j];
     2225    }
     2226  }
     2227  return(minimum);
    22142228}
    22152229example
Note: See TracChangeset for help on using the changeset viewer.