-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Comments
Summary: The |
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). |
@ipr-fredrik2 can you provide repro instructions as mentioned in the comment above. |
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
),
),
),
);
}
}
|
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? |
Physical device, Samsung Tab Active 4 Pro (model number T636B), android-arm64 |
Expected behaviour:
sqrt(0.0) == 0.0
Actual behaviour: Sometimes
sqrt(0.0) == 0.0
, but also sometimessqrt(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"
The text was updated successfully, but these errors were encountered: