Emacs bra size calculator

Emacs bra size calculator

Emacs 文胸尺码计算器

Emacs bra size calculator posted 2026-05-27, updated 2026-05-28. Recently i needed some new bras. My measurements had changed a bit since last time, so to make my life easier(?) i decided to write a bra size calculator that i can use in Emacs.

Emacs 文胸尺码计算器,发布于 2026-05-27,更新于 2026-05-28。最近我需要买些新文胸。由于我的身材尺寸与上次相比发生了一些变化,为了让生活更轻松(?),我决定编写一个可以在 Emacs 中使用的文胸尺码计算器。

The core function, my-math-compute-bra-size, is as follows:

核心函数 my-math-compute-bra-size 如下所示:

;; dependencies - these come with recent Emacs versions but might not be loaded
(require 'calc-units)
(require 'cl-lib)
(require 'seq)

(defun my-math-compute-bra-size (band-expr bust-expr &optional region)
  (cl-flet ((to-unit (expr unit)
              (string-to-number (calc-eval (math-convert-units (calc-eval expr 'raw) (calc-eval unit 'raw) t)))))
    (let* ((region-info-alist
            '((eu . ((unit . "cm") (cups . ((12 . "AA") (14 . "A") (16 . "B") (18 . "C") (20 . "D") (22 . "E") (24 . "F") (26 . "G") (28 . "H") (30 . "I") (32 . "J") (34 . "K")))))
              (uk . ((unit . "in") (cups . ((1 . "AA") (2 . "A") (3 . "B") (4 . "C") (5 . "D") (6 . "DD") (7 . "E") (8 . "F") (9 . "FF") (10 . "G") (11 . "GG") (12 . "H")))))
              (us . ((unit . "in") (cups . ((1 . "AA") (2 . "A") (3 . "B") (4 . "C") (5 . "D") (6 . "DD/E") (7 . "DDD/F") (8 . "DDDD/G") (9 . "H") (10 . "I") (11 . "J") (12 . "K")))))))
           (region (or region 'eu))
           (region-info (alist-get region region-info-alist))
           (unit (alist-get 'unit region-info))
           (cups (alist-get 'cups region-info))
           (band (to-unit band-expr unit))
           (bust (to-unit bust-expr unit))
           (diff (- bust band))
           (cup (or (cdr (seq-find (lambda (x) (< diff (car x))) cups))
                    (format "%s+" (cdar (last cups))))))
      (format "%s%s" (round band) cup))))

This makes use of Emacs Calc’s built-in unit conversion functions, so you need to pass in the measurements as unit-suffixed strings. For example, given a made-up band (underbust) measurement of 90 cm and a bust measurement of 105 cm, you could calculate the EU bra size as (my-math-compute-bra-size "90 cm" "105 cm" 'eu) giving “90B”. You could also use other units of length, such as in (inches), or ly (light years), or Ang (Angstrom). Hooray for Calc!

这段代码利用了 Emacs Calc 内置的单位转换功能,因此你需要以带有单位后缀的字符串形式传入测量值。例如,假设底围(下胸围)测量值为 90 厘米,胸围测量值为 105 厘米,你可以通过 (my-math-compute-bra-size "90 cm" "105 cm" 'eu) 计算出欧盟尺码为 “90B”。你也可以使用其他长度单位,例如 in(英寸)、ly(光年)或 Ang(埃)。为 Calc 欢呼吧!

We can take this further with some nice UI around it. I have recently enjoyed using Org tables as spreadsheets, and wanted to make a table where i can just type in my measurements, refresh, and have EU/UK/US bra sizes automatically filled in. This is not too difficult to achieve by using Emacs Lisp as formulas. You can copy-paste the following table as a template:

我们可以通过添加一些友好的 UI 来进一步完善它。我最近很喜欢将 Org 表格当作电子表格使用,并希望制作一个表格,只需输入测量值,刷新一下,就能自动填入欧盟/英国/美国尺码。通过使用 Emacs Lisp 作为公式,实现这一点并不难。你可以复制粘贴以下表格作为模板:

| date | band | bust | EU size | UK size | US size | |------------+-------+--------+---------+---------+---------| | 2026-05-27 | 90 cm | 105 cm | | | |

#+TBLFM: $4='(my-math-compute-bra-size $2 $3 'eu)::$5='(my-math-compute-bra-size $2 $3 'uk)::$6='(my-math-compute-bra-size $2 $3 'us)

Modify the band and bust numbers (again, with your preferred length units!), update the table, for example with C-u C-c *, and all the size fields get recomputed :) You can also add more rows and keep a log of measurements over time, if you want to.

修改底围和胸围数字(同样,使用你偏好的长度单位!),然后更新表格(例如使用 C-u C-c *),所有的尺码字段都会重新计算 :) 如果你愿意,还可以添加更多行来记录随时间变化的测量数据。

Disclaimers:

  • I implemented support for EU, UK and US sizing as these are the ones i usually encounter. Other standards might need some additional logic.
  • There are larger cup sizes than the ones i entered, but the data i found on them was a bit inconsistent. Sorry! For sizes that are out of range, the function will return the largest known size with a + added. It should hopefully be easy to augment the data if needed.
  • There may be mistakes in my data/code. I know in practice sizes vary by brand, model, etc. But results from online calculators that i tried while writing this post vary so wildly that i now question whether these numbers really mean anything at all.
  • I am reasonably confident my EU size calculation is consistent with EN 13402 though.

免责声明:

  • 我实现了对欧盟、英国和美国尺码的支持,因为这些是我通常接触到的标准。其他标准可能需要额外的逻辑。
  • 存在比我录入的更大的罩杯尺码,但我找到的相关数据有些不一致。抱歉!对于超出范围的尺码,该函数将返回已知的最大尺码并加上一个 ”+” 号。如果需要,扩充数据应该很容易。
  • 我的数据或代码中可能存在错误。我知道在实际中,尺码会因品牌、款式等而异。但在撰写本文时,我尝试的在线计算器给出的结果差异巨大,以至于我现在怀疑这些数字是否真的有意义。
  • 不过,我有相当大的把握认为我的欧盟尺码计算符合 EN 13402 标准。