1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

とりあえず十進固定小数点の平方根でSQRT(20)前後を作ってみた

Last updated at Posted at 2025-03-04
  • れんしゅうで作った
  • 精度は、ほぼない

o_coq830.jpg

プログラム

オンラインコンパイラ



#include <iostream>
using namespace std;

int q_rsqrt(int number) {
    
    long long i;
    long long x2, y;
    long long threehalfs;

    x2 = number * 1000000 / 2;
    y  = number * 1000000;
    threehalfs =  15 * 1000000 / 10;
    
    
    printf("x2 = %lld\n",x2);
    printf("y = %lld\n",y);
    printf("threehalfs = %lld\n",threehalfs);

    y = 304049 - (( 7812 * x2 )/1000000);
    printf("y = %lld\n",y);
    
    i = y * y / 1000000;
    i = x2 * i / 1000000;
    i = threehalfs - i;
    y = y * i / 1000000;
    printf("y = %lld\n",y);
    //y  = y * ( threehalfs - ( x2 * y * y ) );
    return y;
}


int main(void){
    // Your code here!
    
    int in = 20;
    int f;
    
    f = q_rsqrt(in);
    f = in * f;
    printf("%d.%d",f / 1000000,f % 1000000 );

}




x2 = 10000000
y = 20000000
threehalfs = 1500000
y = 225929
y = 223572
4.471440

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?