Hacker News new | past | comments | ask | show | jobs | submit login
0x7FDE623822FC16E6: A magic constant for double float reciprocal (2011) (pvk.ca)
158 points by signa11 on July 22, 2021 | hide | past | favorite | 24 comments



Just one past thread with one past comment:

0x7FDE623822FC16E6 : a magic constant for double float reciprocal - https://news.ycombinator.com/item?id=2335025 - March 2011 (1 comment)


cperciva's comment there also generalizes to cryptographic protocols which sometimes require batch inversion (i.e. given a1, ..., an \in F, find out all a1^{-1}, ..., an^{-1}; e.g. when converting a bunch of EC points from projective to affine coordinates), and is there known as "Montgomery's trick" (separate from Montgomery modular multiplication). That is, you trade n inversions for 3(n-1) multiplications and one inversion.


If your box has avx512, this paper has a neat vectorized double precision reciprocal: http://www.ecs.umass.edu/arith-2018/pdf/arith25_18.pdf

I’ve not tried it yet but I like all the new math instructions.



Looks like the only use on GitHub so far is Gorgonia, a Go ML library, along with a fast tanh function.

https://github.com/gorgonia/gorgonia/blob/master/math_fast.g...


Since when do I have to login to search GitHub code?


The URL triggers an “advanced search” (“Code” only, instead of “All GitHub”). For that, they want your login.


No long required and regex search (not that it is needed here). Plus it searches GitLab too. (I think there is a repo limit though based on popular repos)

https://sourcegraph.com/search?q=context:global+7FDE623822FC...


As mentioned in the article, it reminds me of the 0x5f3759df fast inverse square root used in Quake III Arena!

https://medium.com/hard-mode/the-legendary-fast-inverse-squa...

This is where I really see CS as being close to mathematics.


Ask me how I know you didn’t read the article :)


> As mentioned in the article


Touché, I edited it. I still thought it's worth keeping the comment because people might not always realise how useful these hacks can be when performance is important e.g. games.


i remembered when i wanted to implement sqrt(x) by myself. before concluding that the LLVM instruction was the fastest, i came with this: https://gist.github.com/longemen3000/72b2d18761d1a89fd31a7aa...


That 6E6 on the end looks ironically like a floating-point exponent. :)


When someone asks you what software engineering is, this is software engineering.


FWIW, I would probably call this "applied mathematics"; "software engineering" is a discipline that studies how to create software.


> FWIW, I would probably call this "applied mathematics"

You mean the thing we call "computer science" (or "mathematical informatics" in some non-English-speaking countries)?


This is programming/hacking. Software engineering is more related to the tools and processes an used to build and maintain software.


This is very much engineering, discoving an extremely effective solution based on system knowledge.


One of the biggest eye-openers to me once I hit "the real world" was how many wildly different interpretations of the word "engineering" there are.

At one end of the scale you have people who equate it entirely with methodology and process, and at the other you have people who equate it with building a high performance system.


I really love the totally varied definitions in this thread. THIS pretty much sums up so much of CS.


Engineering would be how you test it, how you document it, how you maintain it, how you deploy it. Implementing other peoples algorithms is just programming/coding.


The problem with that redefinition is that you spontaneously transform into an engineer when working on your own personal library, but as soon as you pull in a single dependency, or manually punch in some old school approximation algorithm, you are "just" some dirty good for nothing code janitor.

Imagine somebody tasked with designing a bridge abandoning their engineering mindset because they used somebody else's drafting table. Also, that engineer better be "just" implementing other peoples algorithms on that bridge design - I'm not interested in driving across some 10Xer's suspension bridge.


I consider tools and processes more like being a code mechanic.

A construction worker is familiar with construction tools and processes. A civil engineer does the math and design work to "program" a building.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: