Home Quake3 List

Can we code the Fast Inverse Root algorithm in every langauge?

The goal of this project is to find an implementation of Quake 3's algorithm for as many languages as possible. You can help by contributing your implementations on the GitHub page. The only requirement is that an implementation follow the same process and does not use any functions that weren't possible at the time, such as division. Code should include a line to invoke the function.

The Algorithm

          
            float Q_rsqrt(float number)
            {
              long i;
              float x2, y;
              const float threehalfs = 1.5F;
    
              x2 = number * 0.5F;
              y  = number;
              i  = * ( long * ) &y; // evil floating point bit level hacking
              i  = 0x5f3759df - ( i >> 1 ); // what da heck?
              y  = * ( float * ) &i;
              y  = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
              // y  = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
    
              return y;
            }
          
        

The algorithm

x86 Assembly

          

          
        

Bash

          

          
        

C/C++

          

          
        

Carbon

          

          
        

Coffee

          

          
        

C#

          

          
        

Dart

          

          
        

Elixir

          

          
        

Fortran

          

          
        

F#

          

          
        

Go

          

          
        

Godot

          

          
        

Haskell

          

          
        

Java

          
       
          
        

JavaScript

          

          
        

Julia

          

          
        

Lua

          

          
        

Mojo

          

          
        

Nim

          

          
        

Perl

          

          
        

PHP

          

          
        

Python

          

          
        

R

          

          
        

Ruby

          

          
        

Rust

          

          
        

Scala

          

          
        

Solidity

          

          
        

Swift

          

          
        

VbScript

          

          
        

Vlang

          

          
        

Zig