[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [CHANGESET]: First attempt at a single precision type.
From: |
Jaroslav Hajek |
Subject: |
Re: [CHANGESET]: First attempt at a single precision type. |
Date: |
Mon, 28 Apr 2008 10:20:15 +0200 |
On Mon, Apr 28, 2008 at 9:57 AM, David Bateman
<address@hidden> wrote:
> David Bateman wrote:
> >
> >> | I've assumed that the correct mixed double/single behavior is to promote
> >> | the single type to double,
> >>
> >> Yeah, you would think that would be the way it should work, but of
> >> course Matlab converts to single.
> >>
> >
> > You're kidding.... That is just incorrect in terms of ensuring a
> > consistent precision. I assume the reason they did this is to allow
> > something like
> >
> > single_arg + function_that_returns_double_for_single_arg(single_arg)
> >
> > to return single. This allows some functions not to be converted to
> > handle singles and the majority of the calculation remaining in single
> > precision. If this is the case there might be a difference between the
> > treatment of operators and functions. For example, what about a mix of
> > single/double arguments to a function like filter or betainc for
> > example, does it promote or demote the returned argument?
> >
>
> I thought about this further and it seems that matlab's behavior for
> mixed operators is
>
> double OP int -> int
> single OP int -> error
> double OP single -> single
>
> We can easily get this behavior but removing the numeric conversion
> methods from the single classes and putting them in the double classes.
> However I see no reason why "single OP int" should be an error, but if
> the numeric conversion methods are removed from the single classes then
> to ensure that it isn't an error we'd have to implement all of the mixed
> single/int operators.. So perhaps complete matlab compatibility is teh
> way to go here :-)
>
> I also tried the mixed types to some functions, such as
>
> >> a = filter (single(1),[1,1], 1:5)
>
> a =
>
> 1 1 2 2 3
>
> >> whos a
> Name Size Bytes Class Attributes
>
> a 1x5 20 single
>
> and it appears that matlab prefers to demote the types if possible. So
> the behavior I currently implemented will need to be up dated.
>
I suggest to think twice, however. You've implemented the most
"normal" or "obvious" behaviour, IMHO. That single+double = single in
Matlab was a surprise for me. Is there anyone who considers the Matlab
behaviour as normal? I mean, I think that almost all other languages
or math systems do it the other way around - promote single to double.
Perhaps even Matlab users are unsatisfied with this behaviour (I think
I've never used single in Matlab, but if I did, certainly I'd have
been disappointed).
Octave has a chance here to go the right way from the beginning, if
this is the case.
--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
- [CHANGESET]: First attempt at a single precision type., David Bateman, 2008/04/27
- Re: [CHANGESET]: First attempt at a single precision type., John W. Eaton, 2008/04/28
- Re: [CHANGESET]: First attempt at a single precision type., Jaroslav Hajek, 2008/04/28
- Re: [CHANGESET]: First attempt at a single precision type., David Bateman, 2008/04/28
- Re: [CHANGESET]: First attempt at a single precision type., John W. Eaton, 2008/04/28
- Re: [CHANGESET]: First attempt at a single precision type., John W. Eaton, 2008/04/28