Floats to strings - emulator vs bug

Help and questions on programming the codebug
Post Reply
mikerr
Posts: 83
Joined: Fri Jul 31, 2015 10:37 am
Contact:

Floats to strings - emulator vs bug

Post by mikerr » Mon Sep 28, 2015 9:22 am

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 ?
Twitter @mikered codebug profile mikerr

BMS Doug
Posts: 61
Joined: Wed Aug 26, 2015 8:54 am
Contact:

Re: Floats to strings - emulator vs bug

Post by BMS Doug » Mon Sep 28, 2015 9:37 am

UhOh, Petey will be cross:
Image

mikerr
Posts: 83
Joined: Fri Jul 31, 2015 10:37 am
Contact:

Re: Floats to strings - emulator vs bug

Post by mikerr » Mon Sep 28, 2015 9:44 am

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).
Twitter @mikered codebug profile mikerr

pigraham
Posts: 65
Joined: Sat Aug 15, 2015 1:41 pm

Re: Floats to strings - emulator vs bug

Post by pigraham » Mon Sep 28, 2015 1:57 pm

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/

mikerr
Posts: 83
Joined: Fri Jul 31, 2015 10:37 am
Contact:

Re: Floats to strings - emulator vs bug

Post by mikerr » Mon Sep 28, 2015 4:35 pm

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/
Twitter @mikered codebug profile mikerr

pigraham
Posts: 65
Joined: Sat Aug 15, 2015 1:41 pm

Re: Floats to strings - emulator vs bug

Post by pigraham » Mon Sep 28, 2015 5:16 pm

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)

moreginger
Posts: 1
Joined: Sun Jan 24, 2016 11:25 am

Re: Floats to strings - emulator vs bug

Post by moreginger » Sun Jan 24, 2016 11:29 am

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/

Post Reply