Add next batch of calculators and AWG support

This commit is contained in:
Codex Agent
2026-03-08 01:49:50 +00:00
parent 68bc636af8
commit e9e5adce42
5 changed files with 128 additions and 45 deletions

View File

@@ -1,5 +1,5 @@
// THIS FILE IS AUTO-GENERATED BY migrate.py
export type CalcType = 'standard' | 'inverse' | '3col' | '3col-mul' | 'base' | 'text-bin' | 'bin-text' | 'dms-dd' | 'dd-dms' | 'dec-frac' | 'db-int' | 'db-spl' | 'db-v' | 'db-w';
export type CalcType = 'standard' | 'inverse' | '3col' | '3col-mul' | 'base' | 'text-bin' | 'bin-text' | 'dms-dd' | 'dd-dms' | 'dec-frac' | 'db-int' | 'db-spl' | 'db-v' | 'db-w' | 'awg' | 'brinell-rockwell';
export interface CalculatorDef {
slug: string;
@@ -1598,6 +1598,11 @@ export const calculators: CalculatorDef[] = [
{"slug": "heat-transfer-coefficient-btu-per-hour-square-foot-f-to-w-per-square-meter-k", "name": "Heat transfer coefficient (BTU/(hr\u00b7ft\u00b2\u00b7\u00b0F)) to W/(m\u00b2\u00b7K)", "category": "energy", "type": "standard", "teaser": "Return imperial coefficients back into SI.", "labels": {"in1": "Heat transfer coefficient (BTU/(hr\u00b7ft\u00b2\u00b7\u00b0F))", "in2": "W/(m\u00b2\u00b7K)"}, "factor": 5.6782633415},
{"slug": "heat-transfer-coefficient-w-per-square-meter-k-to-w-per-square-foot-f", "name": "Heat transfer coefficient (W/(m\u00b2\u00b7K)) to W/(ft\u00b2\u00b7\u00b0F)", "category": "energy", "type": "standard", "teaser": "Move the conduction coefficient into mixed-area and temperature units.", "labels": {"in1": "Heat transfer coefficient (W/(m\u00b2\u00b7K))", "in2": "W/(ft\u00b2\u00b7\u00b0F)"}, "factor": 0.0516128},
{"slug": "heat-transfer-coefficient-w-per-square-foot-f-to-w-per-square-meter-k", "name": "Heat transfer coefficient (W/(ft\u00b2\u00b7\u00b0F)) to W/(m\u00b2\u00b7K)", "category": "energy", "type": "standard", "teaser": "Convert the mixed imperial SI coefficient back into its base units.", "labels": {"in1": "Heat transfer coefficient (W/(ft\u00b2\u00b7\u00b0F))", "in2": "W/(m\u00b2\u00b7K)"}, "factor": 19.3750387506},
{"slug": "awg-to-circular-mils", "name": "AWG to Circular mils", "category": "electrical", "type": "awg", "teaser": "Convert American Wire Gauge sizes into circular mil areas.", "labels": {"in1": "AWG", "in2": "Circular mils"}},
{"slug": "awg-to-millimeters-diameter", "name": "AWG to Millimeters (diameter)", "category": "electrical", "type": "awg", "teaser": "Express AWG gauge as a diameter in millimeters.", "labels": {"in1": "AWG", "in2": "Millimeters (diameter)"}},
{"slug": "awg-to-square-millimeters-cross-section", "name": "AWG to Square millimeters (cross-section)", "category": "electrical", "type": "awg", "teaser": "Convert AWG sizes into cross-sectional area in mm\u00b2.", "labels": {"in1": "AWG", "in2": "Square millimeters (cross-section)"}},
{"slug": "board-feet-energy-equiv-to-btu", "name": "Board feet (energy equiv.) to BTU", "category": "energy", "type": "standard", "teaser": "Convert the energy equivalent of a board foot of lumber into BTUs.", "labels": {"in1": "Board feet (energy equiv.)", "in2": "BTU"}, "factor": 14000.0},
{"slug": "brinell-to-rockwell-c", "name": "Brinell to Rockwell C", "category": "other", "type": "brinell-rockwell", "teaser": "Approximate Rockwell C hardness from Brinell hardness numbers.", "labels": {"in1": "Brinell", "in2": "Rockwell C"}},
];

View File

@@ -181,6 +181,74 @@ export function solve(
out.val1 = (!isNaN(v2) && v2 > 0) ? fmt(10 * Math.log10(v2)) : '';
}
break;
case 'awg': {
const log92 = Math.log(92);
const awgToDiameterMm = (g: number) => 0.127 * Math.pow(92, (36 - g) / 39);
const diameterMmToAwg = (d: number) => 36 - 39 * Math.log(d / 0.127) / log92;
const awgToCircularMils = (g: number) => 1000 * Math.pow(92, (36 - g) / 19.5);
const circularMilsToAwg = (a: number) => 36 - 19.5 * Math.log(a / 1000) / log92;
const awgToAreaMm2 = (g: number) => {
const d = awgToDiameterMm(g);
return Math.PI * Math.pow(d, 2) / 4;
};
const areaMm2ToAwg = (a: number) => {
const d = Math.sqrt((4 * a) / Math.PI);
return diameterMmToAwg(d);
};
const slug = calc.slug;
const formatAwg = (g: number) => isFinite(g) ? fmt(g) : '';
if (slug.includes('circular-mils')) {
if (source === 1) {
out.val2 = !isNaN(v1) ? fmt(awgToCircularMils(v1)) : '';
} else {
out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(circularMilsToAwg(v2)) : '';
}
} else if (slug.includes('square-millimeters')) {
if (source === 1) {
out.val2 = !isNaN(v1) ? fmt(awgToAreaMm2(v1)) : '';
} else {
out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(areaMm2ToAwg(v2)) : '';
}
} else {
// diameter in millimeters
if (source === 1) {
out.val2 = !isNaN(v1) ? fmt(awgToDiameterMm(v1)) : '';
} else {
out.val1 = (!isNaN(v2) && v2 > 0) ? formatAwg(diameterMmToAwg(v2)) : '';
}
}
break;
}
case 'brinell-rockwell': {
// Approximate correlation for steels:
// BHN = (1520000 - 4500 * HRC) / (100 - HRC)^2
if (source === 1) {
// Brinell to Rockwell C
if (!isNaN(v1) && v1 > 0) {
const a = v1;
const disc = 4500 ** 2 + 4 * a * 1070000;
const y = (4500 + Math.sqrt(disc)) / (2 * a);
const hrc = 100 - y;
out.val2 = fmt(hrc);
} else {
out.val2 = '';
}
} else {
// Rockwell C to Brinell
if (!isNaN(v2) && v2 < 100) {
const h = v2;
const bhn = (1520000 - 4500 * h) / Math.pow(100 - h, 2);
out.val1 = fmt(bhn);
} else {
out.val1 = '';
}
}
break;
}
}
return out;

View File

@@ -54,7 +54,7 @@
<section class="hero">
<h1>How Do You Convert?</h1>
<p>Fast, bidirectional unit conversions with no ads.</p>
<p>Fast unit conversions with no ads.</p>
<div class="search-center">
<SearchBar idPrefix="home-search" />
</div>