[comp.lang.perl] Artitmetic functions

jv@mh.nl (Johan Vromans) (02/20/91)

I'd like to suggest adding the following aritmetic functions to perl.

   min(LIST)	- numerically lowest of LIST
   max(LIST)	- numerically highest of LIST
   round(EXPR[,precision])
		- EXPR rounded to precision decimal
		  places (default integer precision)
   ceil(EXPR)	- ceiling value of EXPR
   floor(EXPR)	- floor value of EXPR (identical to 'int')

Reasonable?

	Johan

-- 
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------

tneff@bfmny0.BFM.COM (Tom Neff) (02/22/91)

>   min(LIST)	- numerically lowest of LIST
>   max(LIST)	- numerically highest of LIST

I would not restrict this to numeric context.

	min("def","ghi","abc","jkl")

might profitably return "abc".

_______________________

My opinion of Johan's suggestions in general is that Larry should
implement most of them right away!  They are well in keeping with the
Perl "Swiss Army Guillotine" philosophy.  Better to do it now, before
things get cast in stone.

worley@compass.com (Dale Worley) (02/23/91)

   X-Name: Johan Vromans

   I'd like to suggest adding the following aritmetic functions to perl.

      min(LIST)	- numerically lowest of LIST
      max(LIST)	- numerically highest of LIST

Sounds good.

      round(EXPR[,precision])
		   - EXPR rounded to precision decimal
		     places (default integer precision)
      ceil(EXPR)	- ceiling value of EXPR
      floor(EXPR)	- floor value of EXPR (identical to 'int')

Firstly, 'floor' is not 'int', because floor(-0.5) is -1, while
int(-0.5) is 0.  (Perl's 'int' is not the same as Algol's -- it really
should be called 'trunc'.)

I would like to see the optional 'precision' argument added to 'round',
'ceil', and 'int' as well.  And don't forget that precision can be
negative.

Dale

Dale Worley		Compass, Inc.			worley@compass.com
--
ROM stands for Read-Only Memory, meaning that new things cannot be written
to it; ROM is the silicon equivalent of the brain of a religious fanatic.
-- Lincoln Spector

rbj@uunet.UU.NET (Root Boy Jim) (02/26/91)

In <1991Feb20.113935.14427@pronto.mh.nl> Johan Vromans <jv@mh.nl> writes:
>I'd like to suggest adding the following aritmetic functions to perl.
>
>   min(LIST)	- numerically lowest of LIST
>   max(LIST)	- numerically highest of LIST
>   round(EXPR[,precision])
>		- EXPR rounded to precision decimal
>		  places (default integer precision)
>   ceil(EXPR)	- ceiling value of EXPR
>   floor(EXPR)	- floor value of EXPR (identical to 'int')
>
>Reasonable?

Ahem. Now if Larry would allow functions to follow the same rules
as variable names, we could have:

		&<	min
		&>	max
		&0	round (:-)
		&_	floor
		&^	ceiling
		&!	factorial

And of course, now that we have control character variables:

		&^d	FILEHANDLE can replace close
		&^c	send interrupt to process
		&^z	replaces sleep

Like I said, how hard could it possibly be to parse '&& && &&' :-)

All of your suggestions can be implemented trivially by any user,
so there is really no reason for Larry to do it.
-- 
		[rbj@uunet 1] stty sane
		unknown mode: sane

poage@sunny.ucdavis.edu (Tom Poage) (02/27/91)

Not too much too add ...

	sub floor {
		local($f) = @_;
		int(($f < int $f) ? --$f : $f);
	}

	sub ceil {
		local($f) = @_;
		int(($f > int $f) ? ++$f : $f);
	}
-- 
Tom Poage, Clinical Engineering
University of California, Davis, Medical Center, Sacramento, CA
poage@sunny.ucdavis.edu  {...,ucbvax,uunet}!ucdavis!sunny!poage