Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Numerical accuracy when converting from Single to float #1896

Closed
@m-rossi

Description

@m-rossi

Environment

  • Pythonnet version: 3.0.0rc4
  • Python version: 3.10.5
  • Operating System: Windows 10 20H2
  • .NET Runtime: 6.0.6

Details

  • Describe what you were trying to get done.

    I'm sorry it's me again with some weird low-level issue. I use a DLL where a function returns aSystem.Single. Its return value is0.01. Before pythonnet version 3.0 this got converted to a Pythonfloat also of value0.01. With Pythonnet 3.0 I get a Pythonfloat0.009999999776482582 instead. I can reproduce this issue by creatingSystem.Single objects.

  • What commands did you run to trigger this issue? If you can provide a
    Minimal, Complete, and Verifiable example
    this will help us understand the issue.

    importclrimportSystem# Parse a string to avoid conversion from Python float to dotnetprint(System.Single.Parse('1e-2'))# Create a pure dotnet object without conversion back to Python (I think .ToString() gets called here?)print(System.Single(0.01))# Create a pure dotnet object without conversion back to Python and convert back to Pythonprint(System.Single(0.01).MemberwiseClone())
    0.0099999997764825820.010.009999999776482582

    With pythonnet 2.5.2 this will return

    0.010.010.01

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp