Open ipr-fredrik2 opened 1 week ago
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.
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
),
),
),
);
}
}
@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?
Physical device, Samsung Tab Active 4 Pro (model number T636B), android-arm64
Will mark this as P3 until we are able to reproduce the issue.
//cc @alexmarkov
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"