Spent hours debugging a bug that made zero sense. A simple condition was failing: 4 / 2 == 2 Logically correct. Mathematically correct. Still… failing. No crashes. No obvious errors. Just a silent mismatch breaking the flow. Out of frustration, I printed the value instead of trusting it. 👉 1.999999995 That’s when things clicked. It wasn’t a logic bug. It was a precision problem. Floating-point arithmetic doesn’t guarantee exact values — numbers are stored as binary approximations. And sometimes, that “2” you trust is just… slightly off. That tiny difference was enough to fail an equality check: if (result == 2) → false The fix? ✔️ Avoid direct comparison of floating numbers ✔️ Use a tolerance (epsilon) for comparisons ✔️ Or switch to precise types where exact values matter That day debugging reminded me: The scariest bugs aren’t the ones that crash. They’re the ones that look perfectly correct. And sometimes… 4 / 2 isn’t 2. #SoftwareEngineering #Debugging #Programming #Flutter #Android #Bugs
Debugging a Silent Bug in Floating-Point Arithmetic
More Relevant Posts
-
Brute force works… But it’s not always smart ❌ This problem is a perfect example 👇 👉 Find maximum sum of subarray of size K Naive approach: Check all windows → O(n × k) Optimized approach: Use Sliding Window → O(n) 💡 What changes? You stop repeating work. Instead of recalculating sum every time: → Subtract old element → Add new element That’s it. 👉 Less loops = More efficiency #ProblemSolving #DSA #Coding #Developers
To view or add a comment, sign in
-
-
𝗧𝘆𝗽𝗲 𝗮𝗹𝗶𝗮𝘀𝗲𝘀 𝗮𝗻𝗱 𝘁𝗿𝗮𝗶𝘁𝘀 𝗮𝘀𝘀𝗼𝗰𝗶𝗮𝘁𝗲𝗱 𝘁𝘆𝗽𝗲𝘀 Very recently i came into a problem: How to give a generic argument to a type alias when I don’t have a concrete type available? Let’s take an example: 𝚙𝚞𝚋 𝚝𝚢𝚙𝚎 𝚅𝚒𝚛𝚝𝚞𝚊𝚕𝙷𝚘𝚜𝚝𝚜<𝚅> = 𝙰𝚛𝚌<𝙷𝚊𝚜𝚑𝙼𝚊𝚙<𝚂𝚝𝚛𝚒𝚗𝚐, 𝚅>>; You don’t have V implemented anywhere on this crate, how to refer to VirtualHosts in that case? Solution: Use trait with associated types. Your trait should be something like this: 𝚙𝚞𝚋 𝚝𝚛𝚊𝚒𝚝 𝚂𝚎𝚛𝚟𝚎𝚛 { 𝚝𝚢𝚙𝚎 𝚅𝚒𝚛𝚝𝚞𝚊𝚕𝙷𝚘𝚜𝚝; 𝚏𝚗 𝚟𝚒𝚛𝚝𝚞𝚊𝚕_𝚑𝚘𝚜𝚝𝚜(&𝚜𝚎𝚕𝚏) -> 𝚅𝚒𝚛𝚝𝚞𝚊𝚕𝙷𝚘𝚜𝚝𝚜<𝚂𝚎𝚕𝚏::𝚅𝚒𝚛𝚝𝚞𝚊𝚕𝙷𝚘𝚜𝚝>; } Then in another crate: 𝚙𝚞𝚋 𝚜𝚝𝚛𝚞𝚌𝚝 𝙷𝚝𝚝𝚙𝚂𝚎𝚛𝚟𝚎𝚛 { 𝚟𝚒𝚛𝚝𝚞𝚊𝚕_𝚑𝚘𝚜𝚝𝚜: 𝚅𝚒𝚛𝚝𝚞𝚊𝚕𝙷𝚘𝚜𝚝𝚜<𝚅𝚒𝚛𝚝𝚞𝚊𝚕𝙷𝚘𝚜𝚝>; } 𝚒𝚖𝚙𝚕 𝚂𝚎𝚛𝚟𝚎𝚛 𝚏𝚘𝚛 𝙷𝚝𝚝𝚙𝚂𝚎𝚛𝚟𝚎𝚛 { 𝚝𝚢𝚙𝚎 𝚅𝚒𝚛𝚝𝚞𝚊𝚕𝙷𝚘𝚜𝚝 = 𝚈𝚘𝚞𝚛𝚅𝚒𝚛𝚝𝚞𝚊𝚕𝙷𝚘𝚜𝚝; 𝚏𝚗 𝚟𝚒𝚛𝚝𝚞𝚊𝚕_𝚑𝚘𝚜𝚝(&𝚜𝚎𝚕𝚏) -> &𝚅𝚒𝚛𝚝𝚞𝚊𝚕𝙷𝚘𝚜𝚝𝚜<𝚂𝚎𝚕𝚏::𝚅𝚒𝚛𝚝𝚞𝚊𝚕𝙷𝚘𝚜𝚝> { &𝚜𝚎𝚕𝚏.𝚟𝚒𝚛𝚝𝚞𝚊𝚕_𝚑𝚘𝚜𝚝𝚜; } } #rust #async #traits #programming #performance #network #abstractions
To view or add a comment, sign in
-
Uploading a 2GB file sounds simple. It isn’t? We built a real-time file upload system. Here’s what actually broke: Network drops → uploads failed at 98% Retry logic → duplicated chunks “Resume upload” → corrupted files Large files → memory spikes on server Logs → useless when you need them most What fixed it: Chunking + idempotent APIs Checkpointing (not blind retries) Strict server-side validation Backpressure handling Context-rich logging Lesson? At scale, it’s not about making things work. It’s about making them fail safely. Most systems don’t break on the happy path. They break in the 1% edge cases you ignored. #SoftwareEngineering #Programming #SystemDesign #Scalability #TechLessons
To view or add a comment, sign in
-
Time for a C-Programming Deep Dive! Pointers are often where the gap between "knowing" C and "mastering" C becomes clear. Can you predict the exact output of this code without running it in a compiler? The Challenge: #include <stdio.h> int main() { int arr[] = {10, 20, 30, 40, 50}; int *ptr = arr; printf("%d, ", *ptr++); printf("%d, ", *++ptr); printf("%d, ", ++*ptr); printf("%d", (*ptr)++); return 0; } How to participate: Work out the logic for each printf statement. Drop your answer in the comments below. Explain why the third and fourth outputs are particularly tricky! I’ll be liking the correct answers and posting the full technical breakdown of the operator precedence involved in 24 hours. Let's see who gets it 100% right! 🎯 #CProgramming #EmbeddedSystems #VLSI #CodingChallenge #SoftwareEngineering #Pointers #ProgrammingQuiz
To view or add a comment, sign in
-
I just ran a NES emulator inside a custom OS built on WebAssembly and I'm still a little in disbelief. The goal: build an operating system that uses WebAssembly as its native execution model. Today, that OS booted up, loaded a NES emulator as a WASM module, and started rendering frames.For context, this isn't running in a browser. This is a from scratch kernel, booting on x86_64, with its own memory manager, framebuffer, and WASM runtime.Lots more to build, but milestones like this are what keep you going. https://lnkd.in/g_34KUDR #OpenSource #OperatingSystems #Programming #Emulation #BuildInPublic
To view or add a comment, sign in
-
-
Caldera just got a lot more useful. The focus this time was simple: make the gap between writing code and understanding what the machine actually does as small as possible. The biggest quality-of-life change is that latency and throughput data now live directly in the assembly stream. It sounds small, but not having to flip between views while you're reading makes a real difference to how you think about the code. Assembly extraction is also cleaner now. The compiler-specific sentinel logic has been tightened up — GCC/Clang, MSVC, and Windows Clang all have hardened extraction paths, including a fallback for the COFF quirks you inevitably hit on Windows. The goal is simple: what you see should be your code, nothing else. CUDA support is new in this release. You get PTX for high-level inspection and SASS output via nvdisasm for real hardware visibility — so you're looking at what the GPU actually runs, not just what the compiler thinks it will run. Source ↔ ASM mapping is now bidirectional and works across compilers. Click a source line, see its instructions. Click an instruction, jump back to the source. It falls back gracefully when debug info is thin. The diff engine was replaced with a Myers LCS implementation. Pinned snapshots now produce structurally meaningful diffs instead of line noise — you see what actually changed between two versions. llvm-mca is now a first-class citizen: full pipeline stats (IPC, uOps, cycles), a structured table view, and an inline annotation mode that turns static assembly into something closer to a predictive execution model. Each compiler tab is fully isolated — its own compiler, standard, flags, and architecture. Comparing outputs across toolchains no longer means fighting context bleed. And the whole thing runs locally. No browser, no sandbox, no round-trips. Check it out! https://lnkd.in/guya_7QD #Programming #SoftwareEngineering #Tech #CPlusPlus #OpenSource #SystemsProgramming #PerformanceEngineering #Compilers #GPUProgramming #CUDA
To view or add a comment, sign in
-
-
♻️ Duplication is the root of all evil in software. Here's why. Two API functions. They look solid. Now imagine adding a timeout to 20 of them. Updating them all is painful — but missing even one leaves a silent bug waiting to crash your app. The fix? Extract it. One function handles fetching, error checking, and the timeout. Now getUsers and getPosts just call it with their endpoint. Need to change the timeout? One place. Done. This is the DRY principle — Don't Repeat Yourself. Every piece of knowledge must have a single, unambiguous, authoritative representation within a system. One truth. One place. #CleanCode #Flutter #Dart #DRY #CodeQuality #SoftwareEngineering #Programming #DevTips #100DaysOfCode
To view or add a comment, sign in
-
-
I think I've found coolest use of claude code I've seen so far. Here's a question: suppose every time you run nvidia-smi, you see an ollama process capturing 4gb of your vram. If you kill the process, it just comes back every few minutes at most. - There no extraneous terminal windows open, you're not coding with ollama, nothing. What's wrong? I asked claude about this, and it figured out that every 5 minutes, something was hitting /api/generate on my ollama (11434) endpoint, like a cronjob. It claimed that perhaps it was a vector search extension using ollama in obsidian, but I have literally a million ollama contraptions and random scripts, a well-known extension wouldn't leak so much memory to keep the cache warm. Then, claude proceeded to create a script that watches 11434 for any calls at all, and logs the prompt it uses. ~10 minutes later, the prompt was: "Based on these git changes, suggest a concise commit message following conventional commits format (e.g., "feat:", "fix:", "refactor:", etc.). Only output the commit message, nothing else" It turns out I'd opened VS Code's extension development host to work on another extension, and it also ran a "git commit reminder" extension which was ~a year old. 2 things were learned: 1. VS Code's extension development host seems to run arbitrary extensions or I need to check my config 2. Claude Code is *fantastic* at debugging in your OS, and 12 year old me who loved bash would have her mind blown at how painless that was.
To view or add a comment, sign in
-
-
Ever faced a memory leak… in code or in life? 😂 Post: In C, forgetting to free() memory leads to leaks. In life, forgetting to “let go” does the same. 🔹 Deleted the node 🔹 But memory still occupied That’s not just a bug… that’s emotional engineering 😄 👉 Lesson: Always clean up your pointers (and your past) #CProgramming #LinkedList #MemoryLeak #CodingHumor #SoftwareEngineering #EmbeddedSystems #DebuggingLife #TechMemes #ProgrammerLife
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
This is one of those bugs that humbles you. Direct equality checks on floats are a trap, especially in tests. What looks like a simple assertion can quietly fail and send you chasing the wrong problem. The moment you start comparing within a tolerance instead of exact values, a lot of these “impossible” bugs just disappear.