microsoft / microsoft/pxt-microbit

micro:bit makecode-editor simulator behaves differently from real micro:bit (v2) in the function Math.pow() with floats as exponents.

Open
#4,436 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

apis Simulator
Dominant language
TypeScript
Stars
804
Forks
721
Avg merge
2d 9h
Merged PRs (30d)
2

Description

Describe the bug
The microbit simulators behaviour differs from the microbit behaviour when using Math.pow(a,b) if the exponent (b) is not an integer.

The result of Math.pow(2, 3.5) is 8 on the micro:bit (it only seems to use the integer part (3) instead of (3.5).
Math.pow(2, 3.5) is 11.31370849898476 in the simulator.

To Reproduce
Steps to reproduce the behavior:

  1. run the following code from the makecode.microbit.com javascript editor in the simulator and on a real microbit device.
    '''basic.showNumber(2 ** 3.5)'''
  2. observe the number displayed on the micro:bit.
  3. The real (V2) microbit device will display 8 whereas the simulator will display 11.3137...

Expected behavior
The simulator and microbit must produce the same result.

Either the simulator also uses integers only for the exponent and the result is 8 also in the simulator or
the microbit Math.pow() function has an issue and needs to be fixed to accept float values as well for the exponent part.

  • Which version of the micro:bit is this relevant to [ EG V1.3, V1.5, V2.0, or specify it's not hardware related ]

V2

Desktop (please complete the following information):
The simulator and microbit behaviour does not seem to be os dependent

  • OS: MacOS 12 and LInux (Ubuntu Mate 20.04)
  • Browser Chrome
  • Version 94.0.4606.81 (on Ubuntu)

Additional context
None that seems relevant.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the micro:bit JavaScript editor simulator and reproduce Math.pow(2, 3.5), then compare its result with the V2 device behavior described here. The issue names no source file or test; determine which behavior is intended and make the simulator and device agree, with regression coverage for the reported float exponent case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
devtools, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.