Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Sane or bad decimal format (sharing?)
2011-07-27 15:26
terric
Account closed

Registered: Feb 2009
Posts: 47
Sane or bad decimal format (sharing?)

I latetely finished some code.
And after many hours of thinking i came to the conclusion that saving a value below 1 like 0.75 could be done in a byte. You could almost make a 1.0 by setting all 7 bits in the byte.
My format: MSB is signed bit and the others below has the values 0.5,0.25,0.125 and so on. I got this when repeating mathematics and thought that by describing a value close to real value by setting the bits correct would make a difference.

What if we now have the value of 0.75?
We can describe it as 1/2 + 1/4 yes, so if we edit according bits 6,5 to 1 and the rest to 0 then we have a byte with the value of 0.75 represented as 01100000.

Ideas, good or bad ? ( I have a working times engine unrolled for this byte )

terric
2011-07-27 15:49
chatGPZ

Registered: Dec 2001
Posts: 11130
welcome to fixed point math =)

(and yes its not only a good idea, its the common solution on platforms with no FPU =P)
2011-07-27 20:11
WVL

Registered: Mar 2002
Posts: 886
the discovery of 1/256th ;) Ofcourse this is the only sane way to describe values with which you can do fast math on c64. Disadvantage : try to write some 'common' normal decimal values like 0.1 in this format.. (ok, ofcourse you can get close, but you'll never get there)
2011-07-27 20:39
chatGPZ

Registered: Dec 2001
Posts: 11130
ofcourse the question is... are we really talking about representing *decimal*, or rather *fractions* :)
2011-07-28 02:11
Skate

Registered: Jul 2003
Posts: 491
if you need more sensitivity in fractions, you can use all of the 8 bits. so 0.75 equals to %11000000. but this may require additional case handling when making calculations with negative numbers. so, you should decide which is more important to you. speed or accuracy?
2011-07-28 06:32
JackAsser

Registered: Jun 2002
Posts: 1989
More than often I wish to represent numbers between 0 and 1 inclusive. Anybody got a nice solution to this. Currently I use 8.8-fixpoint, but it feels such a waste using only bit 0 in the upper 8 bits ONLY when it's the number 1. And using more exotic setups like 1.7-fixpoint is not so nice either I think, resulting in some shifts when you need the data.
2011-07-28 08:44
Frantic

Registered: Mar 2003
Posts: 1627
JA: I am not sure why 1.7 fixpoint must necessarily result in shifts? Why not simply treat bit7 as 1? If I do not misunderstand things, if you really need to shift it so that you have a bit0 that stands for the "1" then this is the same as saying that you need to have the 1 in bit0 anyway which probably implies 1.8 fixpoint? Anyway.. please elaborate on your problem. I am sure you could solve it better than me anyway, but it would be interesting to hear.
2011-07-28 09:32
Perplex

Registered: Feb 2009
Posts: 254
Quoting JackAsser
More than often I wish to represent numbers between 0 and 1 inclusive. Anybody got a nice solution to this.


One byte = 0/255 .. 255/255?
2011-07-28 10:12
WVL

Registered: Mar 2002
Posts: 886
Quote: Quoting JackAsser
More than often I wish to represent numbers between 0 and 1 inclusive. Anybody got a nice solution to this.


One byte = 0/255 .. 255/255?


that's even more nasty...
2011-07-28 10:31
Perplex

Registered: Feb 2009
Posts: 254
Quoting WVL
that's even more nasty...

That really depends on what you're using them for, doesn't it?
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
iceout/Avatar/HF
Guests online: 127
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (9.5)
8 Quadrants  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Birth of a Flower  (9.5)
Top Groups
1 Nostalgia  (9.3)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Original Suppliers
1 Black Beard  (9.7)
2 Derbyshire Ram  (9.5)
3 hedning  (9.2)
4 Baracuda  (9.1)
5 Jazzcat  (8.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.05 sec.