STL map impl. in C

Discussion in 'C Programming' started by Swamy Muddu, Jul 23, 2003.

  1. Swamy Muddu

    Swamy Muddu Guest

    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
    Swamy Muddu, Jul 23, 2003
    #1
    1. Advertising

  2. Swamy Muddu

    Tim Prince Guest

    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
    Tim Prince, Jul 23, 2003
    #2
    1. Advertising

  3. Swamy Muddu

    Mr. 4X Guest

    "Swamy Muddu" <> 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
    Mr. 4X, Jul 23, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Timo Qvist

    STL hash_set problem, SGI impl

    Timo Qvist, Nov 18, 2004, in forum: C++
    Replies:
    1
    Views:
    860
    Victor Bazarov
    Nov 18, 2004
  2. Marcus
    Replies:
    2
    Views:
    579
    Marcus
    Dec 9, 2005
  3. Replies:
    2
    Views:
    542
    klaus hoffmann
    Feb 22, 2006
  4. kl
    Replies:
    7
    Views:
    1,276
    James Kanze
    Jan 1, 2008
  5. Luca Risolia

    STL map to STL vector

    Luca Risolia, Jan 13, 2014, in forum: C++
    Replies:
    32
    Views:
    340
    Seungbeom Kim
    Jan 18, 2014
Loading...

Share This Page