Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > STL map impl. in C

Reply
Thread Tools

STL map impl. in C

 
 
Swamy Muddu
Guest
Posts: n/a
 
      07-22-2003
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
 
Reply With Quote
 
 
 
 
Tim Prince
Guest
Posts: n/a
 
      07-23-2003
Swamy Muddu wrote:

> 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.
--
Tim Prince
 
Reply With Quote
 
 
 
 
Mr. 4X
Guest
Posts: n/a
 
      07-23-2003
"Swamy Muddu" <(E-Mail Removed)> wrote:

> 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
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
STL map or hash map using struct as data and find it kl C++ 7 01-01-2008 11:05 AM
a stl map which use stl pair as the key Allerdyce.John@gmail.com C++ 2 02-22-2006 07:25 AM
Copy elements from one STL container to another STL container Marko.Cain.23@gmail.com C++ 4 02-16-2006 05:03 PM
STL: Map of maps possible, but no multi-map of maps? Workarounds? Marcus C++ 2 12-09-2005 06:34 AM
To STL or not to STL Allan Bruce C++ 41 10-17-2003 08:21 PM



Advertisments