It is currently Mon Oct 16, 2017 3:17 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: float-type numbers
PostPosted: Mon Dec 06, 2004 3:06 am 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3064
Location: Brazil
A float number has 4 bytes. How do I save these bytes to disk?
As example, an unsigned short:

Code:
unsigned short bleh = 0xFDCA;

byte1 = bleh & 0xFF;
byte2 = (bleh >> 8) & 0xFF; //or whatever is the endianess...


How would I procceed with a float? TKS

_________________
Zepper
RockNES developer


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 3:10 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1388
If you're writing it to a file:
Code:
float n;
FILE *file;
...
fwrite(&n,1,4,file);


If you're doing something else with it:
Code:
union
{
    float f;
    unsigned long l;
} n;
n.f = 1.0;
printf("%08X",n.l);





But why would you need to deal with any floating point numbers in an NES emulator?

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 3:27 am 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3064
Location: Brazil
That union idea worked fine:

Code:
0x40492492 (3.142857)
size of float = 4


The float? FRAME_TIME / 4 = something.5 ;)

_________________
Zepper
RockNES developer


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 5:40 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19081
Location: NE Indiana, USA (NTSC)
If you're dealing with things being something .5, then try using fixed-point instead of floating-point.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 5:56 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3064
Location: Brazil
tepples wrote:
If you're dealing with things being something .5, then try using fixed-point instead of floating-point.


I have no clue how... unfortunately. Would a float affect the emulation speed?

_________________
Zepper
RockNES developer


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 11:17 pm 
Offline

Joined: Mon Sep 27, 2004 11:51 pm
Posts: 101
How's about using a different time base for the APU core (i.e. multiply cycle counts by 2)?

_________________
http://hydesprojects.cjb.net/


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 20, 2004 5:26 am 
Offline

Joined: Mon Dec 20, 2004 4:51 am
Posts: 6
I doubt you'd have mucb of a preformance hit using float moderatly, unless of course you need to preform an integer float conversion. if you ever cast to int, consider fixed point otherwise, it's not a big deal.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group