Urgent.News

What's breaking now, across thousands of outlets.

Tech

Edge Cases in a Waist-to-Height Ratio Calculator: Units, Rounding, and Boundaries

Waist-to-height ratio (WHtR) looks like the easiest calculator you could write: divide one number by another. It's also a good example of how a "trivial" calculator goes wrong in production. Users type centimeters into an inches box. Floating point makes a value that should sit exactly on a limit land a hair above it. A display rounded to two decimals disagrees with the pass/fail check underneath…

The waist-to-height ratio (WHtR) calculator demonstrates how a simple tool can encounter issues in a real-world setting. Users input measurements in various units, leading to unexpected behavior when the calculator is used in production.

A JavaScript module is presented as an example, illustrating the challenges faced when handling different units and rounding methods. The module's core function converts input values to a single unit (inches) for all calculations, ensuring consistency throughout the process.

A key aspect of the calculator is the comparison against a threshold limit. A small value, called EPS, is used to account for floating-point inaccuracies that can cause values on the limit to be slightly over or under the threshold. This ensures that the calculator's results remain stable despite minor fluctuations in decimal places.

The module also includes a function for determining the maximum waist measurement allowed for a given height and limit. This function rounds down to the nearest tape resolution, which is set to 0.5 inches in the provided examples.

The code includes several test cases to validate the calculator's functionality, ensuring that it correctly handles different input units and bound values. These tests cover scenarios where the ratio is exactly at the limit, slightly above the limit, and when the input units are mixed. Additionally, the code demonstrates how the module handles invalid inputs, throwing appropriate errors when necessary.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Running classic MU Online Season 6 in the browser and on mobile

If you played MU Online back around 2005, you probably remember the setup: downloading a patchy archive, running main.exe , and praying legacy DirectX drivers wouldn't crash.

  • MU Online Season 6 playable in browser and mobile via OpenMU project
  • OpenMU uses C# reimplementation and Babylon.js WebGL engine for rendering
  • Project optimizes assets, handles network bridge, and offers mobile-friendly features

How to Convert JPG to PDF Online for Free: Combine Images into One File

If you're not technical: use the free online tool If you're not a technical person and you're looking for a free way to turn JPG or PNG images into a PDF, use my online image to PDF converter .

  • Free online tool converts JPG/PNG to PDF without installation
  • Upload and arrange images using Add images option
  • Download final PDF with up to 12 images, 60 MB limit

TMview's trademark search has three match modes, not one — and two of them are misnamed

TMview 's search endpoint takes a criteria field in every request: { "page" : "1" , "pageSize" : "50" , "criteria" : "C" , "basicSearch" : "solarwinds" } The web UI always sends "C" , and so did our…

  • TMview search has three match modes: contains, whole word, ends with
  • Contains mode finds any occurrence of search term within a name
  • Whole word mode requires search term to be a standalone word

How to Compress a Video Online for Free: Reduce MP4 File Size

If you're not technical: use the free online tool If you're not a technical person and you're looking for a free way to make a video smaller, use my online video compressor .

  • Online video compressor tool shrinks file size without tech skills
  • FFmpeg re-encodes locally for customized compression approach
  • Duration, bitrate, and resolution impact final compressed size

More from Sunday 1 November →