STL map impl. in C

S

Swamy Muddu

Hi--

Is it possible to index an array using floating point numbers
instead of integers (0 through n)? I have an array M in which
one of the indices is a floating point number. Previously, I used
a dirty work around for conversion of this index into an int
(I found out that this is causing a loss in accuracy).

map<> template in STL can be used to index arrays using strings,
floats etc. Is there any implementation of map<> in C?
Any help would be very helpful to me.

Thanks in advance..

-- S Muddu
 
T

Tim Prince

Swamy said:
Hi--

Is it possible to index an array using floating point numbers
instead of integers (0 through n)? I have an array M in which
one of the indices is a floating point number. Previously, I used
a dirty work around for conversion of this index into an int
(I found out that this is causing a loss in accuracy).

map<> template in STL can be used to index arrays using strings,
floats etc. Is there any implementation of map<> in C?
Any help would be very helpful to me.

Thanks in advance..

-- S Muddu
Perhaps you should write more explicitly what you want:
array[(int)(x)]
array[lrint(x)]
array](int)ceil(x)]
.....
Compilers tend to be lacking in ESP, as am I. Google searching doesn't
enlighten me on any relationship STL map<> might have to C or your
question. Nor am I enlightened as to how you might cast float or double to
int without loss of accuracy.
 
M

Mr. 4X

Swamy Muddu said:
Hi--

Is it possible to index an array using floating point numbers
instead of integers (0 through n)?

IIRC arrays can't be indexed by non-integral expressions (char, int, enum).

You could keep the number in a float and use a rounding function when you
want to index the array.

I have an array M in which
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top