Skip to content

from_json gives incorrect result when float value has negative exponent #376

@totalgee

Description

@totalgee
  • Compiler Used: Xcode 9
  • Operating System: macOS 10.12.6
  • Architecture (ARM/x86/32bit/64bit/etc): x64

Expected Behavior

from_json("35.2e-2") should give 0.352, but gives 35.2.

Actual Behavior

When there is a negative exponent on a JSON-parsed number, it always returns the exponent 0, because parse_num doesn't support negative numbers. The solution will be to fix only the JSON parsing code, because it's too risky to touch the low-level ChaiScript number parsing! (I tried once before ;-)

Minimal Example to Reproduce Behavior

// These all fail as unit tests
assert_equal(from_json("9.9e-02"), 9.9e-02)
assert_equal(from_json("1E-01"), 0.1)
assert_equal(from_json("-314159e-5"), -3.14159)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions