Decimals in a matrix

This is a discussion on Decimals in a matrix within the C++ Programming forums, part of the General Programming Boards category; Is it possible to put decimal values in a matrix? I tried creating a double matrix and I'm not getting ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    5

    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
    Code:
    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
    Location
    Singapore
    Posts
    22,303
    how does it not work?

    btw, perhaps you want to use (r*r) as opposed to (r^2), which is r bitwise-XOR 2.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    Posts
    9,598
    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.

    Code:
    float matrix[3][3];
    
    matrix[0][0]=1.0f;matrix[0][1]=0.0f;matrix[0][2]=0.0f;matrix[0][3]=0.0f;
    matrix[1][0]=0.0f;matrix[1][1]=1.0f;matrix[1][2]=0.0f;matrix[1][3]=0.0f;
    matrix[2][0]=0.0f;matrix[2][1]=0.0f;matrix[2][2]=1.0f;matrix[2][3]=0.0f;
    matrix[3][0]=0.0f;matrix[3][1]=0.0f;matrix[3][2]=0.0f;matrix[3][3]=1.0f;
    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, 02: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 Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 07:36 AM
  4. Matrix Reloaded Questions (SPOILERS_
    By Xei in forum A Brief History of Cprogramming.com
    Replies: 73
    Last Post: 10-19-2003, 03:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21