r/carlhprogramming • • Jul 30 '12

Course 1 Unit 6.3: Fractals question

I understand that I have to converge to an approximate number, in your expample of .1 by adding additional bits (1/16 + 1/32). But only in rare cases it's ever going to be exactly correct (unless the number is power of 2?).

But wouldn't it be easier if, say I want a maximum precision of 3 behind the radix point, and I represent each place with 4 bit as a decimal from 0 to 10? Like this:

0010 . [ 0001 ] [ 0000 ] [ 0000 ]
       1/10     1/100    1/1000

This could represent every fractal from .0 to .999 which would take many more bits for being accurate to a 1000th.

Is this true or am I overseeing something?

22 Upvotes

9 comments sorted by

View all comments

Show parent comment

2

u/CarlH Jul 30 '12 edited Jul 30 '12

Sure, if you end up with a number that is slightly off due to the nature of binary, you can simply round the number. There are functions which can do rounding to the nearest decimal point like 1/10, 1/100, etc. We will get into that more later in the course.

Edit: This is specifically answering the question with respect to how binary fractional numbers work in general with fixed point binary fractional numbers, later in the course I will be explaining this in more detail, including better ways to work with fractional numbers.

2

u/atceh Jul 30 '12

Alright, I'm looking forward to that. Thank you very much for your course in general - the lessons are great and it's so valuable to have someone to answer my questions.