Always getting 0.00 when dividing x with X

14 views
Skip to first unread message

Ognen

unread,
Jan 5, 2022, 11:21:34 AM1/5/22
to FilterMeister Mailing List (FMML)
Hello,

Why the result is always 0.00 when trying to calculate x/X?

%fml

ForEveryTile:{

    float st;

    for(x = x_start; x < x_end; x++){
        st=x/X;
        printf("%f",st);
    }
    return true;
}

Thank you and a Happy New Year

paul simoens

unread,
Jan 5, 2022, 11:32:48 AM1/5/22
to filter...@googlegroups.com

Hi Ognen,

C language sees most int as 0. But if you put it in a calculation or combine it with another float, it will be read as a value.
So you can e.g. try
st =x /X +0.0;

This should work.

 


Regards,
Paul

--
You received this message because you are subscribed to the Google Groups "FilterMeister Mailing List (FMML)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to filtermeiste...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/filtermeister/31d08b7a-e981-4b75-b3b9-5ed7396163ban%40googlegroups.com.

paul simoens

unread,
Jan 5, 2022, 11:50:49 AM1/5/22
to filter...@googlegroups.com

One more thing,
I looked over the fact that int don’t go below 0. Because x <X, the result will unavoidable got stuck at 0.

You can use this:
float fx, fX;

Put this in the running loop
fx =x
fX =X


st =fx /fX;




- - - - - - - - - - - - - - - - - - - - -

Hi Ognen,

C language sees most int as 0. But if you put it in a calculation or combine it with another float, it will be read as a value.
So you can e.g. try
st =x /X +0.0;

This should work.

 


Regards,



Paul

 

Van: filter...@googlegroups.com [mailto:filter...@googlegroups.com] Namens Ognen
Verzonden: woensdag 5 januari 2022 17:22
Aan: FilterMeister Mailing List (FMML)
Onderwerp: [FMML2] Always getting 0.00 when dividing x with X

 

Hello,

--

Ognen

unread,
Jan 5, 2022, 12:18:58 PM1/5/22
to FilterMeister Mailing List (FMML)
Hi Paul,

> st =x /X +0.0
> This should work.
Nope, this doesn't work either

> st =fx /fX
This works. Storing x and X in variables works but not the other way around, when making division alone.

I begin to ask myself is it related to FM semantics because x, y, X, Y are always integers?
When making division when stored in a variables, the floating is allowed, when processing a division with them alone, it cannot process it. Why?

paul simoens

unread,
Jan 5, 2022, 2:14:18 PM1/5/22
to filter...@googlegroups.com

Hi Ognen,

This has nothing to do with FM. Integers are integers due their lack of a fractional part. Because x is always smaller then X, the result will range between 0 and max 1. It act like as you would calculate floor( fx /fX). That would also remain 0.0.

Mixing int with floats needs some care. Try to figure out the range that a particular calculation will make. Therefore I proposed my filterbase, so you can monitor step by step each variable and its result.

Correction of my former mail: integers can go negative, but not for pixel values. I would mean they cut off behind the comma.




Paul

 

 


Verzonden: woensdag 5 januari 2022 18:19
Aan: FilterMeister Mailing List (FMML)

--

You received this message because you are subscribed to the Google Groups "FilterMeister Mailing List (FMML)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to filtermeiste...@googlegroups.com.

Ognen

unread,
Jan 5, 2022, 3:44:59 PM1/5/22
to FilterMeister Mailing List (FMML)
>This has nothing to do with FM. Integers are integers due their lack of a fractional part .
I feel so stupid now that have not remembered to convert x or X into float with (float)x and (float)X. That way it works if divided directly into a user created float variable. All types must be the same is the rule of thumb
So:

float st = (float)x/(float)X;

That will do it.

Thanks for the reminder Paul,
Ognen
Reply all
Reply to author
Forward
0 new messages