help-octave
[Top][All Lists]

## Re: Re: Integer Calculation

 From: Paul Kienzle Subject: Re: Re: Integer Calculation Date: Fri, 28 Jun 2002 09:15:34 -0400

```On Fri, Jun 28, 2002 at 11:00:35AM +0200, address@hidden wrote:
> Hi !
>
> Thanks to Paul Kienzle for his hint !
>
> But there one new question about integer arithmetic.
>
> For unsigned values I need a operation which does 0x0000 - 1 = 0xffff
> (16Bit)

Try:

r = x - floor(x./0x10000).*0x10000;

This should do the correct thing for negative numbers.  It is available
as mod.m in octave-forge (http://octave.sf.net).

>
>
> Is there no way to define a 16Bit (or 32Bit) signed/unsigned Variable
> ?????

The sample program examples/make_int.cc provides an integer type.  You
could modify it to do what you want.  For some reason I had to comment
out the line
octave_value not (void) { ... }
but other than that it works.

Note that this is a very limited example.  There is considerable work
required to turn this into something which does modulo arithmetic on
matrices.

>
>
> Wolfgang
>
>
>
> >Paul Kienzle wrote:
> >
> >Try:
> >
> >     fix(2/3)
> >     fix(4/3)
> >     rem(0xffff+1,0x10000)
> >     rem(0xffff+1,0x100000000)
> >
> >Paul Kienzle
>
> >> On Wed, Jun 26, 2002 at 10:09:40AM -0500, address@hidden
> wrote:
> >> Hi !
> >> I try to use Octave to simulate a velocity controller.
> >> This controller software normaly runs on a 68040 based
> >> board.
> >> The controller made use of 16Bit and 32Bit values
> >> wich can be signed or unsigned.
> >> So when I try to simulate the velocity controller
> >> I have the problem that Octave can't handle 16/32Bit Integer
> >> arithmetik.
> >> Examples (what I need):
> >> 2/3 = 0
> >> 4/3 = 1
> >> 0xffff + 1 = 0 ! (16Bit Value)
> >> 0x0000ffff + 1 = 0x00010000 ! (32Bit Value)
> >> So for some variables I didn't want to use a float value !!
> >> Or is it impossible because every variable inside octave is a flot
> >> value ?
> >> Thanks
> >> Wolfgang
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------
>

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```