Skip to content
This repository has been archived by the owner on Dec 5, 2018. It is now read-only.

text messes up large integers #273

Open
lgto4 opened this issue Dec 1, 2016 · 8 comments
Open

text messes up large integers #273

lgto4 opened this issue Dec 1, 2016 · 8 comments
Labels

Comments

@lgto4
Copy link
Contributor

lgto4 commented Dec 1, 2016

The text function messages up large integer values. For example

var n = 72723460248141;
background(255, 0, 0);
text(n, 100, 100);
println(n);
println(floor(log(n)/log(2)));

shows n to be 72723460248140.992. The work around is ask Javascript to convert the number to a string before invoking text, e.g. text("" + n, ...

@Pomax
Copy link
Member

Pomax commented Dec 4, 2016

Can you add some extra details on how it's messing up? (or include a screenshot showing it doing the wrong thing)

@lgto4
Copy link
Contributor Author

lgto4 commented Dec 4, 2016

@Pomax I updated the complaint to say that 72723460248141 is shown as 72723460248140.992.

@Pomax
Copy link
Member

Pomax commented Dec 6, 2016

Looks like this happens with just text, so a working example:

            void setup() {
                size(400,400);
                noLoop();
            }

            void draw() {
                int n = 72723460248141;
                background(255);
                fill(0);
                text(n, 100, 100);
            }

(note that while technically this has no effect, you don't want var, that's JavaScript. You want int n = ... because you're writing Processing source code)

@Pomax
Copy link
Member

Pomax commented Dec 6, 2016

Ah, I see what's going on. Someone way back when wrote the toP5String function to check for a number based on x == (x|0) which will break when x does not fit in 32 bits, so instead it applies p.nf(obj, 0, 3); which falls back to CommonFunctions.nfCore(), which relies on CommonFunctionsnfCoreScalar() which in turn does some amazingly weird arithmetic to figure out how to serialize the input to a number.

This looks like it needs a check for typeof val === "number" rather than relying on value conversion by forcing a 32 bit operation.

@Pomax Pomax added the bug label Dec 6, 2016
@GoToLoop
Copy link
Contributor

GoToLoop commented Dec 6, 2016

... you don't want var, that's JavaScript.

Well, @lgto4 uses Khan's Academy Pjs spin-off, which goes w/ JS syntax in place of Java's. :-P

@lgto4
Copy link
Contributor Author

lgto4 commented Dec 6, 2016

@GoToLoop lol. What does the "js" in "processing-js" stand for?

@Pomax
Copy link
Member

Pomax commented Dec 6, 2016

Processing interpreter written in JavaScript - the .js is the extension for the library itself, which is written in JavaScript, not for the source code it interprets, which is Processing =)

(sometimes no big deal like here, sometimes a huge deal)

Also note that I can't comment on any branches that aren't this one: I have no idea what other people are doing in their own forks, so if it's a bug in this project (which it is), cool. If it's only a bug in someone else's fork, they'll have to fix it (not the case here)

@mik-jozef
Copy link

The text function also crashes whole tab if called like this: text(Infinity, 20, 20).

(Example on khanacademy; happens on other websites that use ProcessingJs, too)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants