Jarkko Hietaniemi <[EMAIL PROTECTED]> wrote:

> [some quick very high-level comments]
> 
> Don't forget bigrats.

I'm not too familiar with the concept of rational numbers in a computing
complex. What's your definition of a (big)rat? Fixed point??


> > 2) in general we want the result of a binop to be of the
> > same type as the 'biggest' of its operands, eg
> > 
> > $real + $int                        is a real
> > $int + $real                        is a real
> > $bigint + $int                      is a bigint
> > $real + $complex            is a complex
> > $complex + $bigcomplex              is a bigcomplex
> 
> Well, kinda.  But sometimes it is perfectly fine or even desirable to
> 'collapse' back to the 'smaller' kind: when computing with bigints and
> bigrats.  In other words, I would like 
> 87238382456823758823554867875243 - 87238382456823758823554867875242
> to be int (an IV) 1, not a bigint 1.

Perhaps 2) should have been better phrased as

2) in general a binop should cause the op method associated with the
'biggest' of its operands to be called.

Having said that, should an operator ever return an SV of something
other than its own type - especially when it has no context to know
what might be useful to the caller?

IE should bigint_subtract(bigint1,bigint2)

1) always return a new bigint SV
2) a bigint normally, but an int if it happens to know that its result
   will fit in a standard int, or
3) a bigint or an int depending on some as yet undefined external context?

My own feeling is that it should just stick with (1) - if someone has some
code that uses bigints, the chances are that the results of bigint expressions
are most likely to fed into further bigint expressions, so demoting
to int then promoting again would probably less efficient;  also if
you're working with bigints in the first place, then I'd expect cases
where the result of an op fits in an IV would be the minority.
But never having worked with bigints myself, I could be speaking from
my derierre ;-)

I guess ops should be allowed to do (2) if they want; I just personally
think its a bit messy.


* Dave Mitchell, Operations Manager,
* Fretwell-Downing Facilities Ltd, UK.  [EMAIL PROTECTED]
* Tel: +44 114 281 6113.                The usual disclaimers....
*
* Standards (n). Battle insignia or tribal totems

Reply via email to