SynthMaker

rndint()

Archive · 2005 7 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

sambean ·

Just noticed..

rndint(x - 0.5);

doesn't seem to be working in my code as it should..

I'm having to use

temp1 = x - 0.5; rndint(temp1);

Keep up the good work!

Sam

Shifrin ·

Umm, excuse me for saying this, but rndint(x - 0.5) would take an input of say 3.33 and round it to 2 (i.e. 3.33 - 0.5 = 2.83, truncated to 2) - is that what you're wanting to do?! (If yes I'd be interested to see why 😉)

Oh yeah, I seem to remember having the same problem as the one you just described!

Shif.

sambean ·

Hi Shif,

Sorry, I misread your last post in the other thread.. I thought you said it would be round to the nearest integer..

I did a bit of investigating though and I think this is the case,

If you have some code like

x = x + 0.1; xint = rndint(x); xfrac = x - xint; out = xfrac;

and analyse the output, you get both positive and negative numbers.

This suggests that x is being rounded to the nearest integer, and not down (rounding down should only give only positive numbers..)

I may be wrong though, it would be good to get some clarification..

This hovever separate from the

rndint(x - 0.5);

issue, which I think may be a bug..

Cheers

Sam

Shifrin ·

sambean wrote: If you have some code like

x = x + 0.1; xint = rndint(x); xfrac = x - xint; out = xfrac;

and analyse the output, you get both positive and negative numbers.

This suggests that x is being rounded to the nearest integer, and not down (rounding down should only give only positive numbers..)

Ah, I see, according to the synthmaker docs rndint(a) Rounds to the nearest integer value below. So it seems the docs are wrong!

Now I see why you subtract 0.5, I do the same in some assembler code I wrote to calculate pow(x,n) when I needed to truncate (round down).

Just checked it myself, SM's rndint(N) functions is indeed rounding to the nearest integer and *NOT* rounding down to the nearest integer. SM docs are wrong 😉

Shif.

malc ·

Shifrin wrote: So it seems the docs are wrong!

😮 surely not 😉

Will correct at the very next opportunity. Apologies for the confusion.

Shifrin ·

Cheers malc 😉

Shif.

Mue ·

sambean wrote: Just noticed..

rndint(x - 0.5);

doesn't seem to be working in my code as it should..

I'm having to use

temp1 = x - 0.5; rndint(temp1);

Keep up the good work!

Sam

Now the rndint-function definetely rounds to the nearest integer, but the upper description seems still to be true, unfortunately. If the argument of the function is an operation itsself the result seems to pass the rndint-function without any effect.

The last two lines produce the same result of x = 1.8 in my test codes:

float x; x = 2.3; x = rndint(x - 0.5); x = x - 0.5;

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.