Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqrt(0.0) sometimes, but only sometimes, returns NaN #57047

Open
ipr-fredrik2 opened this issue Nov 7, 2024 · 6 comments
Open

sqrt(0.0) sometimes, but only sometimes, returns NaN #57047

ipr-fredrik2 opened this issue Nov 7, 2024 · 6 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@ipr-fredrik2
Copy link

Expected behaviour: sqrt(0.0) == 0.0

Actual behaviour: Sometimes sqrt(0.0) == 0.0, but also sometimes sqrt(0.0).isNaN

Can be tested by simply evaluating this a bunch of times, and print or breakpoint or whatever if its true
sqrt(0.0).isNaN

From math.dart

Dart SDK version: 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "windows_x64"

@dart-github-bot
Copy link
Collaborator

Summary: The sqrt(0.0) function inconsistently returns either 0.0 or NaN. This behavior is observed when repeatedly evaluating the function, suggesting a potential issue with the implementation or underlying floating-point operations.

@dart-github-bot dart-github-bot added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Nov 7, 2024
@julemand101
Copy link
Contributor

What platform are you running the program on? (web? compiled? jit?). Can you post an example program which you have used to reproduce the issue? (I have tried a few times but can't reproduce it).

@devoncarew devoncarew removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Nov 7, 2024
@a-siva a-siva added the needs-info We need additional information from the issue author (auto-closed after 14 days if no response) label Nov 7, 2024
@a-siva
Copy link
Contributor

a-siva commented Nov 7, 2024

@ipr-fredrik2 can you provide repro instructions as mentioned in the comment above.

@ipr-fredrik2
Copy link
Author

I ran the application on Android yesterday in debug mode when I produced the issue, using a breakpoint + log message in an if statement. I was able to trigger the issue several times, fully restarting the application in between.

I can't seem to be able to reproduce this today for whatever reason, neither in my actual application or in a minimal repro. I have no idea what happened. I've restarted my equipment since then, maybe hardware issue or something else weird?

I can come back to this thread if I manage to trigger it again, feel free to close this issue in the meantime.

Here's a minimal reproducable example that should in theory recreate the issue, given the same unknown circumstance that happened yesterday:

import 'package:flutter/material.dart';
import 'dart:math';
import 'dart:developer' as dev;

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  void _onPressed(){
    double gamma = 144.5; // fluff
    for(int i = 0; i < 1024; i++)
    {
      double alpha = 14 * i.toDouble(); // fluff
      double beta = alpha * gamma; // fluff
      if(sqrt(0.0).isNaN)
      {
        dev.log("(sqrt(0.0) was NaN), beta: $beta");
      }
    }
    
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: TextButton(
            child: const Text('Hello World!'),
            onPressed: _onPressed
          ),
        ),
      ),
    );
  }
}

@github-actions github-actions bot removed the needs-info We need additional information from the issue author (auto-closed after 14 days if no response) label Nov 8, 2024
@julemand101
Copy link
Contributor

@ipr-fredrik2

I ran the application on Android yesterday in debug mode when I produced the issue,

Just for the details, can you specify if you was running this in inside an emulator or physical device? Also, which CPU architecture was this running as?

@ipr-fredrik2
Copy link
Author

Physical device, Samsung Tab Active 4 Pro (model number T636B), android-arm64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants