The C Containers library

Value arrays are a group of containers that store the basic types of the
language: short, int, long, long long, float, double, long double
and have some specialized operations that should be done in hardware
when the underlying CPU allows it. The objective here is to simplify the
vector interface replacing the void * with the concrete type that these
arrays hold.

This is a very rich interface with all operations necessary to
realize any general purpose computation fast and efficiently.

ValArrays implement also "Slices", patterned exactly like their
C++ counterparts but with a much easier interface:

You set a slice into the array with "SetSlice", and then all
operations will work ONLY in the selected slice obtaining the
same result as the C++

As you can see, some operations are implemented in some ValArrays,
others aren't. For instance the Inverse function doesn't make any sense
with integers, since for all integers bigger than one it will be zero.

The same with FCompare that compares using Knuth's proposal floating
point numbers using a fuzzy comparison that defines a range around each
number to allow for much finer precision in the comparison.

After more or less a year of work the project starts looking quite usable.

I have again posted this project in the French standardization
committee, and will start discussing it shortly.

Advertisements

Advertisements

<snip>
> As you can see, some operations are implemented in some ValArrays,
> others aren't. For instance the Inverse function doesn't make any
> sense with integers, since for all integers bigger than one it will be
> zero.

Multiplicative inverses exist for unsigned types in C. It may not make
any sense to implement them, but the concept is well defined.

Le 23/04/11 13:56, Ben Bacarisse a écrit :
> jacob navia<> writes:
>
> <snip>
>> As you can see, some operations are implemented in some ValArrays,
>> others aren't. For instance the Inverse function doesn't make any
>> sense with integers, since for all integers bigger than one it will be
>> zero.
>
> Multiplicative inverses exist for unsigned types in C. It may not make
> any sense to implement them, but the concept is well defined.
>
> <snip>

Mmmm I do not understand at all. For all unsigned integers 0..N
where N == UNSIGNED_MAX

That's because integer division is not the inverse of integer
multiplication. The multiplicative inverse of an unsigned int u is an
unsigned int i such that u * i == 1. (For a type T that promotes, the
test would be (T)(u * i) == 1 otherwise multiplication is not closed.)

On 2011-04-23, Ben Bacarisse <> wrote:
> That's because integer division is not the inverse of integer
> multiplication. The multiplicative inverse of an unsigned int u is an
> unsigned int i such that u * i == 1. (For a type T that promotes, the
> test would be (T)(u * i) == 1 otherwise multiplication is not closed.)

u has an inverse only if u and the modulus (UINT_MAX+1) are coprime.
For the typical case where UINT_MAX+1 is a power of two, an even number
has no inverse.

Le 23/04/11 20:08, Ike Naar a écrit :
> On 2011-04-23, Ben Bacarisse<> wrote:
>> That's because integer division is not the inverse of integer
>> multiplication. The multiplicative inverse of an unsigned int u is an
>> unsigned int i such that u * i == 1. (For a type T that promotes, the
>> test would be (T)(u * i) == 1 otherwise multiplication is not closed.)
>
> u has an inverse only if u and the modulus (UINT_MAX+1) are coprime.
> For the typical case where UINT_MAX+1 is a power of two, an even number
> has no inverse.

jacob navia wrote:
> Le 23/04/11 20:08, Ike Naar a écrit :
>> On 2011-04-23, Ben Bacarisse<> wrote:
>>> That's because integer division is not the inverse of integer
>>> multiplication. The multiplicative inverse of an unsigned int u is an
>>> unsigned int i such that u * i == 1. (For a type T that promotes, the
>>> test would be (T)(u * i) == 1 otherwise multiplication is not closed.)
>>
>> u has an inverse only if u and the modulus (UINT_MAX+1) are coprime.
>> For the typical case where UINT_MAX+1 is a power of two, an even number
>> has no inverse.
>
> Do you know of a reference to code calculating that inverse?

Google "extended Euclidean algorithm". The idea is that in computing the gcd
of two numbers n and m, you can simultaneously find two numbers x and y
satisfying

In article
<>,
Ben Bacarisse <> wrote:
> jacob navia <> writes:
>
> <snip>
> > As you can see, some operations are implemented in some ValArrays,
> > others aren't. For instance the Inverse function doesn't make any
> > sense with integers, since for all integers bigger than one it will be
> > zero.
>
> Multiplicative inverses exist for unsigned types in C. It may not make
> any sense to implement them, but the concept is well defined.

If the largest unsigned int is 3, what is the
multiplication table? The usual one has no inverse for 2.

As pointed out by Ike, only for odd n.
> After your message I researched a bit the algorithms for calculating it
> and most say that "this algorithm will return the multiplicative inverse
> if it exists"...
>
> Should I implement that for ValArrayUINT/ValARrayULLong ? It looks quite
> interesting, and the applications are mostly in cryptography. Maybe that
> should go into a special crypto package.

I doubt that it is worthwhile. I can't think of any other uses and the
cryptographic uses will typically use number systems larger than C's
built-in types and which will usually be a finite field (in which every
non-zero element has an inverse).

Once upon a time, I had the idea of trying to write a GNU-style gcd utility.
Among the features were to be:
* calculation of greatest common divisors (obviously)
* calculation of least common multiples
* calculation of least common divisors
* calculation of greatest common multiples
* network support allowing a client/server setup
* the option of specifying more than one port, in which
case the network port used would be their greatest common
divisor
* a mail reader, because every GNU utility needs one

Le 24/04/11 13:30, Seebs a écrit :
> Once upon a time, I had the idea of trying to write a GNU-style gcd utility.
> Among the features were to be:
> * calculation of greatest common divisors (obviously)
> * calculation of least common multiples
> * calculation of least common divisors
> * calculation of greatest common multiples
> * network support allowing a client/server setup
> * the option of specifying more than one port, in which
> case the network port used would be their greatest common
> divisor
> * a mail reader, because every GNU utility needs one
>
> -s

That was the WHOLE contribution of Seebs to this discussion.

It shows his great intellectual capacity and the level at which the
"regulars" move...

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!