octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: std in NDArrays


From: David Bateman
Subject: Re: std in NDArrays
Date: Thu, 26 Aug 2004 16:56:58 +0200
User-agent: Mutt/1.4.1i

According to John W. Eaton <address@hidden> (on 08/26/04):
> I was really thinking about rewriting these operations in C++ in a way
> that would avoid the need to do any evals or funny operations on the
> names of the types.

The problem with rewritting them in C++ is that you'd have to effectively
reimplement the the bitand, bitor and bitxor functionality within these
seperate functions. As script files we can use the existing bitand, etc
functions more easily. This also reduces the risk of getting things wrong.

There is now only a single "eval" in these functions, that is really quite
clear...

Ok, funny operations on type names I'll give you.. But this is no reason to
convert to C++. If you really really want to get rid of both eval and the
funny ops on typenames, then something like

  if strcmp (cname, "double")
    Bmax = bitmax;
    Amax = log2 (Bmax) + 1;
    _conv = @double;
  else
    if strcmp (cname, "uint8")
      Amax = 8;
      _conv = @uint8;
    elseif strcmp (cname, "uint16")
      Amax = 16;
      _conv = @uint16;
    elseif strcmp (cname, "uint32")
      Amax = 32;
      _conv = @uint32;
    elseif strcmp (cname, "uint64")
      Amax = 64;
      _conv = @uint64;
    elseif strcmp (cname, "int8")
      Amax = 8;
      _conv = @int8;
    elseif strcmp (cname, "int16")
      Amax = 16;
      _conv = @int16;
    elseif strcmp (cname, "int32")
      Amax = 32;
      _conv = @int32;
    elseif strcmp (cname, "int64")
      Amax = 64;
      _conv = @int64;
    else
      error ("bitcmp: invalid class %s", cname);
    endif
    Bmax = intmax (cname);
  endif

will get rid of all of it, but at the cost of longer and to me a less 
clear code block...

> 
> Also, I don't think we should do any arithmetic on octave_int64 types
> as long as the rules for those operations are not the same as for the
> other octave_intX types because there is no simple way to implement the
> saturation rules.

As for saturations, the only arithmetic operations on the integer types
are of the form

   Bmax - _conv (_conv (2) .^ (_conv (n) - Aone))

The test

  m = _conv (n(:));
  if (any (m < Aone) || any (m > Amax))
    error ("n must be in the range [1,%d]", Amax);
  endif

causes an error for the values of n that would cause any problems. So there
can be no saturate as this is implicitly an error.

Regards
David

-- 
David Bateman                                address@hidden
Motorola CRM                                 +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax) 
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



reply via email to

[Prev in Thread] Current Thread [Next in Thread]