GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Conversation

Notices

  1. Embed this notice
    Rich Felker (dalias@hachyderm.io)'s status on Friday, 27-Mar-2026 00:09:52 JST Rich Felker Rich Felker

    Floating point puzzle time. Suppose you have two floating point numbers A and B you want to add, but with the result A+B rounded to fewer (a predetermined specific number) mantissa bits than what are available in the type you're working with.

    Are there any tricks to do this, possibly using some biases, that don' t amount to just doing "full soft-float"? I don't see an obvious way.

    In conversation about 6 months ago from hachyderm.io permalink
    • Embed this notice
      Rich Felker (dalias@hachyderm.io)'s status on Friday, 27-Mar-2026 00:14:02 JST Rich Felker Rich Felker
      in reply to
      • Joe Groff

      @joe That's a double-rounding - the addition already rounded once and now you're rounding again. The goal is to get the rounding of the exact result a+b, not the rounding of a rounding.

      In conversation about 6 months ago permalink
    • Embed this notice
      Joe Groff (joe@f.duriansoftware.com)'s status on Friday, 27-Mar-2026 00:14:03 JST Joe Groff Joe Groff
      in reply to

      @dalias if you're ok with the default rounding mode, i think you could do `result + 0x1.0pNNN - 0x1.0pNNN` to push the significand bits you don't want off the edge

      In conversation about 6 months ago permalink
    • Embed this notice
      Rich Felker (dalias@hachyderm.io)'s status on Friday, 27-Mar-2026 00:19:37 JST Rich Felker Rich Felker
      in reply to
      • I Can't Believe It's Not Zero!

      @steve Round-to-nearest is the interesting case. The other rounding modes make double rounding idempotent.

      In conversation about 6 months ago permalink
    • Embed this notice
      I Can't Believe It's Not Zero! (steve@discuss.systems)'s status on Friday, 27-Mar-2026 00:19:38 JST I Can't Believe It's Not Zero! I Can't Believe It's Not Zero!
      in reply to

      @dalias Do you have any control over the magnitude of A and B? Do you want round-to-nearest?

      In conversation about 6 months ago permalink
    • Embed this notice
      Rich Felker (dalias@hachyderm.io)'s status on Friday, 27-Mar-2026 00:21:50 JST Rich Felker Rich Felker
      in reply to
      • Joe Groff

      @joe It's not that easy because you don't know the bias needed until you know the exponent of the result. Which potentially changes under different ways of rounding.

      In conversation about 6 months ago permalink
    • Embed this notice
      Joe Groff (joe@f.duriansoftware.com)'s status on Friday, 27-Mar-2026 00:21:52 JST Joe Groff Joe Groff
      in reply to

      @dalias i see. if A and B fit within single precision, you could promote to double precision and pre-bias one of the operands with 0x1pNNN so that the result gets rounded at the right point. trying to think if there's a way to get the effect without promoting to a higher-precision intermediate type…

      In conversation about 6 months ago permalink
    • Embed this notice
      Rich Felker (dalias@hachyderm.io)'s status on Friday, 27-Mar-2026 00:22:10 JST Rich Felker Rich Felker
      in reply to
      • I Can't Believe It's Not Zero!

      @steve This is actually part of a thought experiment for "can we make decently efficient, non-excess-precision float/double arithmetic on ld80-only archs?"

      In conversation about 6 months ago permalink
    • Embed this notice
      Rich Felker (dalias@hachyderm.io)'s status on Friday, 27-Mar-2026 00:26:31 JST Rich Felker Rich Felker
      in reply to
      • I Can't Believe It's Not Zero!

      @steve GCC's -fsoft-float generates calls to __add[sd]f3, etc., so if you could implement versions of those in terms of hard float but with the right rounding applied, you'd have a trivial-to-integrate solution.

      I'm mainly thinking of this from a standpoint of hosting language interpreters for languages where floating point arithmetic is central, which are currently just broken entirely on 32-bit x86 and m68k. This includes lua, php, javascript, and even qemu I think.

      In conversation about 6 months ago permalink
    • Embed this notice
      Rich Felker (dalias@hachyderm.io)'s status on Friday, 27-Mar-2026 00:45:20 JST Rich Felker Rich Felker
      in reply to
      • I Can't Believe It's Not Zero!

      @steve I guess you can just do the addition and double-round except when the result was on an exact boundary case, and only fallback to a slow path then. The constant-time folks would hate it but it's probably very fast overall.

      In conversation about 6 months ago permalink
    • Embed this notice
      I Can't Believe It's Not Zero! (steve@discuss.systems)'s status on Friday, 27-Mar-2026 00:45:21 JST I Can't Believe It's Not Zero! I Can't Believe It's Not Zero!
      in reply to

      @dalias probably not "decently efficient" in a way that's meaningfully better than soft float. You can conditionally do SW fixup to round to odd in 80bit then round-trip to memory to get the rounding, but it's pretty meh.

      In conversation about 6 months ago permalink
    • Embed this notice
      Rich Felker (dalias@hachyderm.io)'s status on Friday, 27-Mar-2026 00:58:32 JST Rich Felker Rich Felker
      in reply to
      • I Can't Believe It's Not Zero!
      • Joe Groff

      @joe @steve The Win32 ABI is just broken. There is no "double precision mode" on x87. The mode they call that has 53-bit mantissas but 15-bit exponents, not 11-bit ones, except that they get crunched to 11-bit on store to memory. This makes for a far worse mess to clean up, as you not only have double roundings but a new type that behaves as if rounding took place in a different type that nominally doesn't exist and that you can't really access.

      In conversation about 6 months ago permalink
    • Embed this notice
      Joe Groff (joe@f.duriansoftware.com)'s status on Friday, 27-Mar-2026 00:58:34 JST Joe Groff Joe Groff
      in reply to
      • I Can't Believe It's Not Zero!

      @dalias @steve the Win32 ABI kicks `long double` to the curb and keeps the x87 permanently in double precision mode. i don't suppose there's any appetite for a gcc ABI variant that does something similar

      In conversation about 6 months ago permalink

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.