Seite 277 von 340 ErsteErste ... 177 227 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 327 ... LetzteLetzte
Zeige Ergebnis 8.281 bis 8.310 von 10174

C/C++ Programming Help Thread

This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Zitat von cruisx How can i make it so that the cliffs have collision detection too? I know how to ...

  
  1. #8281
    QJ Gamer Silver
    Points: 8.717, Level: 62
    Level completed: 89%, Points required for next Level: 33
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Ort
    Melbourne, Australia
    Beiträge
    1.773
    Points
    8.717
    Level
    62
    My Mood
    Amused
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von cruisx






    How can i make it so that the cliffs have collision detection too? I know how to do it for the sides of the map but i was wondering how it can be done for various parts of the maps? I just want to know, now its in my head and i keep thinking about it lol. By the way i am using oslib and have just started to learn to code for the psp =\. would someone be kind enough to answer my question?
    Look for Box-Line collision on Google.
    Someone said that earlier, sorry forgot who :o


    WHA!?

  2. #8282
    Points: 4.209, Level: 41
    Level completed: 30%, Points required for next Level: 141
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Beiträge
    9
    Points
    4.209
    Level
    41
    Downloads
    0
    Uploads
    0

    Standard

    I have got a error when i try to compile.


  3. #8283
    It's good to be free...
    Points: 10.420, Level: 67
    Level completed: 93%, Points required for next Level: 30
    Overall activity: 0%

    Registriert seit
    Feb 2007
    Beiträge
    2.440
    Points
    10.420
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    :facepalm:
    You spelled debug wrong.
    pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ

  4. #8284
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    *Sigh* have you even tried seeing what the error is?

    pspdebub does not exist, is exactly true, its pspdebug.

    -Aura

    EDIT: Archaemic beat me to it :Argh:
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  5. #8285
    QJ Gamer Platinum
    Points: 66.627, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Overall activity: 0%

    Registriert seit
    Feb 2006
    Ort
    National Front Disco
    Beiträge
    13.057
    Points
    66.627
    Level
    100
    Downloads
    0
    Uploads
    0

    Standard

    I think you spelt pspdebug.h wrong in the include, you wrote:

    Code:
    #include <pspdebub.h>
    When it should be:

    Code:
    #include <pspdebug.h>
    EDIT: Beaten...

  6. #8286
    Points: 4.209, Level: 41
    Level completed: 30%, Points required for next Level: 141
    Overall activity: 0%

    Registriert seit
    Jan 2006
    Beiträge
    9
    Points
    4.209
    Level
    41
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Moose Island
    I think you spelt pspdebug.h wrong in the include, you wrote:

    Code:
    #include <pspdebub.h>
    When it should be:

    Code:
    #include <pspdebug.h>
    EDIT: Beaten...

    Sorry for this stupid action of me i am just a starter but thanks.

  7. #8287
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    I have the address of a function of mine which is not working, and I want to link a new function in its place. I think I found a post a while ago showing the same basic idea, where it replaced the address of the function in memory,and I've been searching for close to an hour to find it again with no luck. Can anyone give me some example code or link me to the post again if you somehow know the post? The post, IIRC, was about getting sceKernelExitGame to link to the devs shell, and to not exit to the XMB instead, incase thats of any help.

    Thanks.
    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  8. #8288
    Ænima
    Points: 6.447, Level: 52
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Sep 2007
    Beiträge
    587
    Points
    6.447
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    I have the address of a function of mine which is not working, and I want to link a new function in its place. I think I found a post a while ago showing the same basic idea, where it replaced the address of the function in memory,and I've been searching for close to an hour to find it again with no luck. Can anyone give me some example code or link me to the post again if you somehow know the post? The post, IIRC, was about getting sceKernelExitGame to link to the devs shell, and to not exit to the XMB instead, incase thats of any help.

    Thanks.
    -Aura
    I don't know how, but I remember that thread also.

    I've got a couple questions

    I think that's it.
    [IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]

    Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.

  9. #8289
    QJ Gamer Blue
    Points: 4.296, Level: 41
    Level completed: 73%, Points required for next Level: 54
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Beiträge
    132
    Points
    4.296
    Level
    41
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von BigSanFrey
    Someone said that earlier, sorry forgot who :o

    ok thanks, ill see if box-line collision helps me and if i understand it =)

    also someone else told me to use his, just wondering what you guys think..

    Code:
    typedef enum
       {
          TILE_PLAYER=1,
          TILE_GRASS=2...ETC
       }
    
    inline int getCurrentTileType(const int& x,const int& y,const map& themap)
    {
    
       return (((x>=themap.width() ||y>=themap.height() ||y<0||x<0)?-1 :themap.tiles[y][x]));
    }
    
    inline void getTilePos(const int& wanted_tile,int& px,int& py,const map& themap)
    {
            px=-1,py=-1;
       int x=0,y=0;
            for (y=0;y<themap.height();y++)
       {
            for (x=0;x<themap.width();x++)
       {
          if ( getCurrentTileType(px,py,themap) != wanted_tile ) continue;
               px = x;
               py = y;
                    return;
                   
       }
       }
    
    
    }
    
    
    
     
    
    int main()
    {
          map themap;
    
          while(running)
          {
     
                   int player_x,player_y,current_tile;
         
             getTilePos(TILE_PLAYER,player_x,player_y,themap);
             current_tile = getCurrentTileType(player_x,player_y,themap);
             if(current_tile == TILE_GRASS)
             {
                //COLLISON! do whatever..
             }
              if(timer.diff() >= 10)..cleanup render etc..
             
          }
    }

  10. #8290
    Ænima
    Points: 6.447, Level: 52
    Level completed: 49%, Points required for next Level: 103
    Overall activity: 0%

    Registriert seit
    Sep 2007
    Beiträge
    587
    Points
    6.447
    Level
    52
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von cruisx
    ok thanks, ill see if box-line collision helps me and if i understand it =)

    also someone else told me to use his, just wondering what you guys think..

    Code:
    typedef enum
       {
          TILE_PLAYER=1,
          TILE_GRASS=2...ETC
       }
    
    inline int getCurrentTileType(const int& x,const int& y,const map& themap)
    {
    
       return (((x>=themap.width() ||y>=themap.height() ||y<0||x<0)?-1 :themap.tiles[y][x]));
    }
    
    inline void getTilePos(const int& wanted_tile,int& px,int& py,const map& themap)
    {
            px=-1,py=-1;
       int x=0,y=0;
            for (y=0;y<themap.height();y++)
       {
            for (x=0;x<themap.width();x++)
       {
          if ( getCurrentTileType(px,py,themap) != wanted_tile ) continue;
               px = x;
               py = y;
                    return;
                   
       }
       }
    
    
    }
    
    
    
     
    
    int main()
    {
          map themap;
    
          while(running)
          {
     
                   int player_x,player_y,current_tile;
         
             getTilePos(TILE_PLAYER,player_x,player_y,themap);
             current_tile = getCurrentTileType(player_x,player_y,themap);
             if(current_tile == TILE_GRASS)
             {
                //COLLISON! do whatever..
             }
              if(timer.diff() >= 10)..cleanup render etc..
             
          }
    }
    In my Lua tile engine, that's how I did collision detection. And IMO, it's a very fast and easy way.
    [IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]

    Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.

  11. #8291
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Judas
    I don't know how, but I remember that thread also.

    I've got a couple questions

    I think that's it.
    Yep, in one, thanks for that :)

    @cruisx:
    Thats, in my opinion, the easiest and quickest method of 2D collision, I only use Box-Line collision for 3D and the method you posted for 2D collisions.

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  12. #8292
    QJ Gamer Blue
    Points: 4.296, Level: 41
    Level completed: 73%, Points required for next Level: 54
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Beiträge
    132
    Points
    4.296
    Level
    41
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    Yep, in one, thanks for that :)

    @cruisx:
    Thats, in my opinion, the easiest and quickest method of 2D collision, I only use Box-Line collision for 3D and the method you posted for 2D collisions.

    -Aura

    ok sweet =p.this might sound noobish but can i use that in Oslib or do i have to convert it for it to work?

  13. #8293
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    That method should work just fine in OSLib I believe, I use the method with graphics.c and OSLib is similar in the way it acts.

    -Aura
    -= Double Post =-
    My code, in another module to my existing faulty code:

    Code:
    int load_MUSIC(char bpath[], int clockA, int clockB);
    
    int load_MUSIC_patched(char bpath[], int clockA, int clockB)
    {
    	// Corrected code
    }
    
    int module_start()
    {
    	*((unsigned int *)load_MUSIC) = J(load_MUSIC_patched);
    	return 0;
    }
    
    int module_stop(void)
    {
    	return 0;
    }
    The above code works if its directly done into the main Project4 code, but when its done from an external module it crashes the PSP. My assumption is that the address not correct.

    I have used a stub file:
    Code:
    	.set noreorder
    
    #include "pspstub.s"
    
    	STUB_START "Project4Stub",0x40090000,0x00010005
    	STUB_FUNC  0x7DD2EC2C,load_MUSIC
    	STUB_END
    is the underlined pointer the address in memory which the function will be loaded (I doubt because isn't the memory dynamic?), or is it the NID? If its the NID, is there a function to find the memory location using the NID?

    -Aura
    Geändert von Auraomega (03-25-2008 um 02:47 PM Uhr) Grund: Automerged Doublepost
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  14. #8294
    QJ Gamer Blue
    Points: 4.296, Level: 41
    Level completed: 73%, Points required for next Level: 54
    Overall activity: 0%

    Registriert seit
    Jul 2006
    Beiträge
    132
    Points
    4.296
    Level
    41
    Downloads
    0
    Uploads
    0

    Standard

    can someone help me out with the collision detection? I made it so that it works for the walls but i am a bit confused on how to use this code for various parts of the map, sorry for all the questions, it is my first time and i don't understand some of the stuff.





    like for example the wood fence.




    Code:
    typedef enum
       {
          TILE_PLAYER=1,
          TILE_GRASS=2...ETC
       }
    
    inline int getCurrentTileType(const int& x,const int& y,const map& themap)
    {
    
       return (((x>=themap.width() ||y>=themap.height() ||y<0||x<0)?-1 :themap.tiles[y][x]));
    }
    
    inline void getTilePos(const int& wanted_tile,int& px,int& py,const map& themap)
    {
            px=-1,py=-1;
       int x=0,y=0;
            for (y=0;y<themap.height();y++)
       {
            for (x=0;x<themap.width();x++)
       {
          if ( getCurrentTileType(px,py,themap) != wanted_tile ) continue;
               px = x;
               py = y;
                    return;
                   
       }
       }
    
    
    }
    
    
    
     
    
    int main()
    {
          map themap;
    
          while(running)
          {
     
                   int player_x,player_y,current_tile;
         
             getTilePos(TILE_PLAYER,player_x,player_y,themap);
             current_tile = getCurrentTileType(player_x,player_y,themap);
             if(current_tile == TILE_GRASS)
             {
                //COLLISON! do whatever..
             }
              if(timer.diff() >= 10)..cleanup render etc..
             
          }
    }




    heres my code

    Code:
    //OSlib header file
    #include <oslib/oslib.h>
    
    //Include the Data part of the map
    #include "Ocean.h"
    
    //Necessary to create eboot
    PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
    PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
    
    //declaration of the pointers of our images
    OSL_IMAGE *sprite, *Ocean_tileset;
    
    //declaration of the pointers of our Map
    OSL_MAP *Ocean;
    
    //definitions
    #define DOWN   0
    #define UP     35
    #define RIGHT  70
    #define LEFT   105
    
    //variables
    int sprite_position;
    int sprite_march;
    int i;
    
    
    //function declarations
    void Buttons();
    void SpriteAnimate();
    
    int main()
    {
        //Initialization of the Oslib library
        oslInit(0);
    
        //Initialization of the graphics mode
        oslInitGfx(OSL_PF_8888, 1);
    
            //Shows the psp-hacks hombrew competition splash screen
            oslShowPSPHacksLogo();
    
        //Sets the transparency color (pink)
        oslSetTransparentColor(RGB(255,0,255));
    
        //loads our images into memory
            Ocean_tileset = oslLoadImageFile("tileset.png", OSL_IN_RAM, OSL_PF_5551);
        sprite = oslLoadImageFile("sprite.png", OSL_IN_RAM, OSL_PF_5551);
    
        //Disables the transpaent color (pink)
        oslDisableTransparentColor();
    
        //verification that all files are present
        if (!sprite || !Ocean_tileset)
            oslDebug("It is impossible to load one or more of the images that are required in this program. Please make sure you have all the files required in the eboot folder");
    
    //configuration of the Map
            Ocean = oslCreateMap(
            Ocean_tileset,                        //Tileset
            Ocean_map,                            //Map
            16,16,                                //Size of the tiles
            64,65,                                //Size of the Map
            OSL_MF_U16);                        //Format of the Map
    
            //Sets the sprite's original position on the screen
        sprite->x = 155;
        sprite->y = 95;
        sprite_position = DOWN;
    
        //main while loop
        while (!osl_quit)
        {
            //To be able to draw on the screen
            oslStartDrawing();        
            
            //calls the Buttons() function
            Buttons();
    
                    //Draws the Map on the screen
            oslDrawMapSimple(Ocean);    
    
            //Draw the images to the screen
            oslDrawImage(sprite);
    
            //Ends drawing mode
            oslEndDrawing();
    
            //Synchronizes the screen
            oslSyncFrame();        
        }
        
        //Terminate the program
        oslEndGfx();
        oslQuit();
        return 0;
    }
    
    
    void Buttons()
    {
        //initiate the PSP's buttons
        oslReadKeys();
       
         //Takes a screenshot of the PSP's screen 
         if (osl_keys->pressed.select)
        oslWriteImageFilePNG(OSL_SECONDARY_BUFFER, "screenshot.png", 0);
    
    //Basic border collision
    if (sprite->x <= 0)
     sprite->x = 0;
    
    if (sprite->y <= 0)
     sprite->y = 0;
    
    if (sprite->x >= 460)
     sprite->x = 460;
    
    if (sprite->y >= 239)
     sprite->y = 239;
    
    if (osl_keys->held.down)
        {
            Ocean->scrollY += 8;
            sprite->y += 1;
            sprite_position = DOWN;
            SpriteAnimate();
        }
    
        if (osl_keys->held.up)
        {
            Ocean->scrollY -= 8;
            sprite->y -= 1;
            sprite_position = UP;
            SpriteAnimate();
        }
        
        if (osl_keys->held.right)
        {
            Ocean->scrollX += 8;
            sprite->x += 1;
            sprite_position = RIGHT;
            SpriteAnimate();
        }
            if (osl_keys->held.left)
        {
            Ocean->scrollX -= 8;
            sprite->x -= 1;
            sprite_position = LEFT;
            SpriteAnimate();
        }
            
        
    
        //If a button is not pressed
        if (!osl_keys->held.value) 
        {
        //Start the variable over for when a button is pressed again
            sprite_march = 0; 
    
            //Sets the sprite's direction
            oslSetImageTileSize(sprite,0,sprite_position,22,35);
        }
    }
    
    
    
    
    void SpriteAnimate()
       {    
            //Moves the sprite in the row that it is in
            sprite_march++;
    
    
            //Moves the sprite constantly with no static position
            oslSetImageTileSize(sprite,(sprite_march * 22),sprite_position,22,35);
    
            //resets the sprite movement in that row
            if (sprite_march == 6) sprite_march = 0;
        
    }

  15. #8295
    QJ Gamer Blue
    Points: 5.871, Level: 49
    Level completed: 61%, Points required for next Level: 79
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Beiträge
    432
    Points
    5.871
    Level
    49
    Downloads
    0
    Uploads
    0

    Standard

    hey if i wanted to splash an image, what kind of could would i use. this is for the computer. im having a real hard time finding it on google.

    thanks

  16. #8296
    Banned for LIFE
    Points: 18.744, Level: 86
    Level completed: 79%, Points required for next Level: 106
    Overall activity: 0%

    Registriert seit
    Oct 2006
    Ort
    East London, England
    Beiträge
    2
    Points
    18.744
    Level
    86
    Downloads
    0
    Uploads
    0

    Standard

    what lib are you using?

  17. #8297
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    How can I set the formatting on a float? I have the presision set as high as I need it, but I was wondering if there was any way to remove the trailing zeros when they are not needed?

    Code:
    	.set noreorder
    
    #include "pspstub.s"
    
    	STUB_START "Project4Stub",0x40090000,0x00010005
    	STUB_FUNC  0x7DD2EC2C,load_MUSIC
    	STUB_END
    is the underlined pointer the address in memory which the function will be loaded (I doubt because isn't the memory dynamic?), or is it the NID? If its the NID, is there a function to find the memory location using the NID?

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  18. #8298
    QJ Gamer Bronze
    Points: 8.045, Level: 60
    Level completed: 48%, Points required for next Level: 105
    Overall activity: 0%

    Registriert seit
    Aug 2007
    Ort
    Australia
    Beiträge
    659
    Points
    8.045
    Level
    60
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    How can I set the formatting on a float? I have the presision set as high as I need it, but I was wondering if there was any way to remove the trailing zeros when they are not needed?
    Hey,
    Im not sure i quite understand you but if you do 0.%f it will get rid of the 0's so the number is displayed like an integer. For example:
    Code:
    float a;
    a = 10.0;
    pspDebugScreenPrintf("0.%f", a);
    will display 10 instead of 10.000...

    Just a quick question, iv written a small function to remove a given colour from an image using graphics.h. Problem is that putPixelImage() doesnt support alpha colours so how else could i go about changing the pixel colour to transparent?

  19. #8299
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    From memory:
    Code:
    float a = 10.3425465577;
    printf("0.%f", a); // 10
    printf("0.2%f", a); // 10.34
    printf("5.2%f", a); // 00010.34

  20. #8300
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Yeah, but doesn't that way remove them completely? I have presision set to what value I need, but when not all digits after the decimal point are being used I want to remove the trailing zeros, not completely remove them altogether. If theres no way to do this with formatting, would there be any way to check the significant figures, and make the length equal to this value? (I know you can change the length with a variable, I'm just not sure how to check the length).

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  21. #8301
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Zitat Zitat von Auraomega
    Yeah, but doesn't that way remove them completely?
    No, why would it if it isn't writing to the variable?

  22. #8302
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Hmm, let me put it another way now I have more time to explain:
    Code:
    float e = 2.71;
    
    printf("%5.5f", e) // 2.71000
    printf("%5.2f", e) // 2.71
    The first output gives trailing zeros, the second output is what I am actually aiming for (without the trailing zeros), I can't set the presision to what is needed, as the value used will actually be dynamic.

    (Oh, and 5.2%f is incorrect, the presision should go between the % and the f, not before, else you get 5.2[value], and the %5.2 doesn't appear to give zeros in front of the number).

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  23. #8303
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Honestly, I don't think you can due the IEEE format. In addition, 2.71 might actually be 2.710000000000000001 due to the nature of floating points.

  24. #8304
    Developer
    Points: 7.577, Level: 58
    Level completed: 14%, Points required for next Level: 173
    Overall activity: 0%

    Registriert seit
    Mar 2006
    Beiträge
    1.026
    Points
    7.577
    Level
    58
    Downloads
    0
    Uploads
    0

    Standard

    First of all I have to ask why you need to do this, perhaps there is a better method to achieve your goal.

    Also, I generally use fabs() for things like this.

    Check out my homebrew & C tutorials at http://insomniac.0x89.org/
    Coder formerly known as Insomniac197

    tshirtz: what is irshell ??
    Atarian_: it's where people who work for the IRS go when they die

  25. #8305
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    I'm trying to throw together a basica calculator, and to keep it to some level of presision, I'm needing to use floats, when the answer has been found it becomes the next value, thus meaning the first and last value at least have to have presision. Theres probably a better way, but for the 10 odd minutes I've spent overall making it, I've not thought of one, and since creating it I've been working on other things.

    Also, isn't fabs just modulus?

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  26. #8306
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    C or C++?

    Edit: Actually, don't iostream and printf output float values up to the first trailing 0 by default?

  27. #8307
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    I'm currently using C, and its a small tool in a big project, so I can't really turn it into C++ even if theres an easy solution.

    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  28. #8308
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    One REALLY roundabout method I can think of is to convert the float to a char string and transverse from the end of the string to the front looking for '0's until it hits a non '0' character and place a null terminator there.

    I see if I can whip up an example.

  29. #8309
    I'm back!
    Points: 8.236, Level: 61
    Level completed: 29%, Points required for next Level: 214
    Overall activity: 99,0%

    Registriert seit
    Feb 2007
    Ort
    England
    Beiträge
    902
    Points
    8.236
    Level
    61
    Downloads
    0
    Uploads
    0

    Standard

    Hmm, that definatly seems a good idea, and I can't believe I hadn't thought of it myself, it wouldn't even be that hard to make, I'll get onto that right away.

    Thanks.
    -Aura
    Last.fm | Deviant Art | First working OS picture

    Zitat Zitat von nickxab Beitrag anzeigen
    I will beat myself. :p

  30. #8310
    QJ Gamer Silver
    Points: 10.263, Level: 67
    Level completed: 54%, Points required for next Level: 187
    Overall activity: 0%

    Registriert seit
    Jun 2006
    Ort
    UK
    Beiträge
    2.326
    Points
    10.263
    Level
    67
    Downloads
    0
    Uploads
    0

    Standard

    Remember what I said about floats and precision? Well it is highlighted by what we are trying to do:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
    	const int BUFFER_SIZE = 128;
    	char buffer[BUFFER_SIZE] = "";
    	float aFloat = 3.65000f;
    	snprintf( buffer, BUFFER_SIZE-1, "%.128f", aFloat );
    	buffer[BUFFER_SIZE-1] = '\0';
    	
    	printf( buffer );
    	printf( "\n" );
    	
    	for( int i = strlen(buffer) - 1; i >= 0 && buffer[i] == '0'; --i )
    	{
    		buffer[i] = '\0';		
    	}
    	
    	printf( buffer );
    	
    	return 0;
    }
    Output:
    Code:
    3.6500000953674316406250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    3.650000095367431640625


 

Tags for this Thread

Forumregeln

  • Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
  • Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
  • Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
  • Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
  •  





Alle Zeitangaben in WEZ -8. Es ist jetzt 09:28 PM Uhr.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © , Caputo Media, LLC. All Rights Reserved. Cluster .