Some utilitarian modules (also: float point error?)
Archive · 20059 old posts
From the original SynthMaker forum (2004–2014), with its members’ names and dates.
grease ·
Here's a few modules that are kind of bland but are the types of operations you have to do frequently. The Max/Min Knobs have edit fields on them so you can enter parameters on the GUI.
I don't know if they are useful for finished projects - I made them more for testing things, experimenting, etc.
One strange thing - note the error on the rightmost knob - it's not due to the construction - I guess it's one of those "floating point errors" that the programming people here probably know and love, but which I don't know much about. Is there a quick and easy, standard way to get rid of this? Perhaps you could take a look inside and see if there is a way to resolve it.
some_modules.osm
lalo ·
many thanx man very useful stuff 🙂
stefan ·
You just need to change the order of some of your calculations 🙂
Do it like this instead and it'll probably work.
grease ·
Hmmm...no, your schematic will always produce an integer multiple of ticks - I want the minimum value plus an integer multiple of ticks. For example, if I set the min to 0.00123, and the tick to 1, I want the knob output to take values 0.00123, 1.00123, 2.00123,...etc.
By the way, what is the resolution of the knob output for the default knobs? I'm sure I can find that out somewhere...I'll go look.
grease ·
I found the part where the error occurs. SynthMaker computes (21)*(0.05)+(-1) to be 0.0500001. You can set up a simple schematic with float operations only to observe this. This must be something related to float point arithmetic I don't understand.
stefan ·
Oh. Ok. Then it takes some more thinking. Hm. If I figure something out, I'll let you know.
More info:
It's not your fault grease 🙂
stefan ·
grease wrote: I found the part where the error occurs. SynthMaker computes (21)*(0.05)+(-1) to be 0.0500001. You can set up a simple schematic with float operations only to observe this. This must be something related to float point arithmetic I don't understand.
We were on the same track 🙂
grease ·
stefancrs wrote:
grease wrote: I found the part where the error occurs. SynthMaker computes (21)*(0.05)+(-1) to be 0.0500001. You can set up a simple schematic with float operations only to observe this. This must be something related to float point arithmetic I don't understand.
We were on the same track 🙂
Ha! We were doing exactly the same thing...
rl ·
I think the internal float representation of -1 rather represents something like -0.9999999, hence the error.
You could truncate some fractional digits or use a more clever calculation to round up/down:
e.g. if you want two fractional digits (out of my head, not tested)
multiply by 100
if fractional >= 0.5 add 1
convert to integer (removes fractional)
convert back to float
divide by 100
Wrote something here? To have a post removed or your name hidden, write to [email protected].