Coder Social home page Coder Social logo

error with modulo operator about orangec HOT 3 CLOSED

ladsoft avatar ladsoft commented on June 1, 2024
error with modulo operator

from orangec.

Comments (3)

LADSoft avatar LADSoft commented on June 1, 2024

Hi lionfaith!

in some contexts, constant propagation for the modulous function was
behaving incorrectly. I have fixed it in the 6.04 release on my web site.

David

lionfaith wrote:

Hello David!
I stepped upon a strange behavior of modulo operator which I could
reduce to this sample:

#include <stdlib.h>
#include <stdio.h>

class Math {
private:
Math(){}
public:
static int rrand(int min,int max)
{
int r = min;
max++;
if ((max - min) ==0)
return min;
r +=rand() % ( max - min );
return r;
}
};

void main(void) {
printf("value: %d",Math::rrand(-3,3) );
}

Value should be between -3 and 3, but it is as if |%| didn't work.
Strangest of all is that making this change:

int delta;
r += rand() % ( delta = max - min );

did remove the bug from the project I am compiling while it does not
remove it from the small excerpt I gave you up above. Putting the
definition of |class Math| in a header is not enough to change that
fact. I just don't understand what changes the behavior.

I hope it helps,
Lionfaith


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#27, or mute the thread
https://github.com/notifications/unsubscribe-auth/AETkIZG03OGzNnbH5m8ArfujemJ_7Uduks5qgLN3gaJpZM4JkptU.

from orangec.

lionfaith avatar lionfaith commented on June 1, 2024

Hi David,
thanks for the work you do so fast!

It was actually a long standing bug for the game I want to compile. It seems to work pretty well now.

Lionfaith

from orangec.

LADSoft avatar LADSoft commented on June 1, 2024

Hi lionfaith,

you're welcome!

the vast majority of the time I end up making small tweaks to the
compiler to fix bugs, it is rare that I have a bug that takes deep
rework like the ones related to the compile time issue you had recently :)

I really appreciate that you dig into the issues and can usually isolate
them to a small example; that makes it much easier on me.

David

lionfaith wrote:

Hi David,
thanks for the work you do so fast!

It was actually a long standing bug for the game I want to compile. It
seems to work pretty well now.

Lionfaith


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#27 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AETkIRtR3WzjnL6zUo0DYYU60vWLp7Biks5qgRbqgaJpZM4JkptU.

from orangec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.