Page 1 of 1

Floats to strings - emulator vs bug

Posted: Mon Sep 28, 2015 9:22 am
by mikerr
pigraham wrote: get string sprite operates like a stream to convert numeric variables to strings. You can "print" a variable by scrolling it across the LED array.
Unfortunately I just found that numeric decimals only work on the emulator, not on a real bug:

3.141592 => "3.141592" on emulator, but truncated to just "3" on a real codebug:

Image
http://www.codebug.org.uk/explore/codeb ... culate-pi/

Not sure which behavior is correct / by design ?

Re: Floats to strings - emulator vs bug

Posted: Mon Sep 28, 2015 9:37 am
by BMS Doug
UhOh, Petey will be cross:
Image

Re: Floats to strings - emulator vs bug

Posted: Mon Sep 28, 2015 9:44 am
by mikerr
A bit more investigation shows the real->string gives a whopping 16 decimal places in the emulator:

http://www.codebug.org.uk/explore/codeb ... ring-test/

Not sure if that's the full maths precision or just string conversion (4 figures would be better for a real->string conversion)

It's 0 decimal places on a codebug (converts to integer).

Re: Floats to strings - emulator vs bug

Posted: Mon Sep 28, 2015 1:57 pm
by pigraham
Does CodeBug handle reals at all? Set variable to a decimal and it shows the integer equivalent.
I assumed it is integer only. Floating point would be overkill for such a simple device.

How are you defining your real values?

Seems to be integer only on the bug.

http://www.codebug.org.uk/explore/codeb ... eger_only/

Re: Floats to strings - emulator vs bug

Posted: Mon Sep 28, 2015 4:35 pm
by mikerr
Seems to be 16bit signed integers which freely overflow

counting up from 32767:
32767 + 1 = "-"
then adding 1 loops to -32767

http://www.codebug.org.uk/explore/codeb ... rflow-fun/

Re: Floats to strings - emulator vs bug

Posted: Mon Sep 28, 2015 5:16 pm
by pigraham
mikerr wrote:Seems to be 16bit signed integers which freely overflow

counting up from 32767:
32767 + 1 = "-"
then adding 1 loops to -32767

http://www.codebug.org.uk/explore/codeb ... rflow-fun/
I see the same, on the bug. The emulator doesn't overflow.

Interestingly the scrolled text outputs :
32767
-
-32767
-32766
...

I.e. an extra '-' on it's own for what might have been -32768 (0x8000)

Re: Floats to strings - emulator vs bug

Posted: Sun Jan 24, 2016 11:29 am
by moreginger
The overflow bug also breaks the "Mikes Dice" [1] project that is linked from http://www.codebug.org.uk/learn/activit ... oard-game/.

Amusingly, debugging this has captured my son's interest most of all, so far :D

[1] http://www.codebug.org.uk/explore/codeb ... ikes-dice/