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: 11386
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: 902
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: 11386
ofcourse the question is... are we really talking about representing *decimal*, or rather *fractions* :)
2011-07-28 02:11
Skate

Registered: Jul 2003
Posts: 494
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: 2014
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: 1648
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: 255
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: 902
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: 255
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
FunFun/Triangle
Mihai
Bieno/Commodore Plus
Andy/AEG
ΛΛdZ
Freeze/Blazon
Guests online: 103
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Mutetus  (9.7)
3 Jeroen Tel  (9.7)
4 Linus  (9.6)
5 Stinsen  (9.6)

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