Thread: Decimals in a matrix

  1. #1
    Registered User
    Join Date
    Oct 2004

    Decimals in a matrix

    Is it possible to put decimal values in a matrix? I tried creating a double matrix and I'm not getting what I want.

    For example
    double A[1][3];
    A[0][0] = 2 *(x + x1);
    A[0][1] = 2 *(y + y1);
    A[0][2] = sqrt(r^2 - (x + x1)^2 - (y + y1)^2);
    It's just not working at all and I don't seem to be making any headway. Turning them into ints loses data, and normalizing it (these are vectors) will just give me (0,0,0) everywhere. What am I supposed to do?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    how does it not work?

    btw, perhaps you want to use (r*r) as opposed to (r^2), which is r bitwise-XOR 2.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    And a bitwise XOR on a double is a nasty beast. In fact I'm surprised the thing compiled.

    Yes you can put non-integral data types in arrays. A matrix is one use for arrays, but in all actuality your question boils down to: Can you use floating point values in arrays?

    Yes. If you couldn't Direct3D and OpenGL would not be possible. They specifically use floating point matrices as well as floating point colors, vectors, texture coords, and a host of other floating point structures.

    float matrix[3][3];
    This should work just fine. Print the array out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Matrix and vector operations on computers
    By DavidP in forum A Brief History of
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM
  4. Matrix Reloaded Questions (SPOILERS_
    By Xei in forum A Brief History of
    Replies: 73
    Last Post: 10-19-2003, 02:21 PM