Join us on IRC @ irc.r00tsecurity.org #r00tsecurity [ Web Client ] [ Log In | Register ]  
Resource Database Index -> Source Code -> P4Math
Description // Info



Source Code

  1. /*
  2.  
  3.  
  4. P4Math functions for use in encryption ect...
  5.  
  6. by P4ll4t0n
  7.  
  8. */
  9.  
  10. //-------------------------------------------------------------------------------------
  11. // BEGIN P4MATH.h
  12. //-------------------------------------------------------------------------------------
  13.  
  14. #define P4MAX( a, b ) ( a > b ? a : b )
  15. #define P4MIN( a, b ) ( a < b ? a : b )
  16. #define P4ABS( a ) ( a < 0 ? -1 * a : a )
  17. #define P4FLOOR( a ) ( (int)( a - 0.5) )
  18. #define P4CEIL( a ) ( (int)( a + 0.5 ) )
  19.  
  20. //Gets the Greatest common divisor of a and b
  21. int P4Gcf( long int a, long int b );
  22.  
  23. //Gets the factorial of a number
  24. long int P4Factorial( long int a );
  25.  
  26. //Simple does a exponents only does whole number exponents
  27. long int P4Pow( int n, int e );
  28.  
  29. //Aprox's the sqrt of a number, the > iters is the more acurate the sqrt is
  30. float P4AproxSqrt( float num, int iters );
  31.  
  32. //------END P4Math.h
  33.  
  34. //------------------------------------------------------------------------
  35. // Start P4Math.c
  36. //------------------------------------------------------------------------
  37. #include "./P4Math.h"
  38. int P4Gcf( long int a, long int b )
  39. {
  40.     int max = P4MAX( a, b );
  41.     int min = P4MIN( a, b );
  42.     int remain;
  43.    
  44.     while( min != 0 )
  45.     {
  46.            remain = max % min;
  47.            
  48.            max = min;
  49.            min = remain;
  50.     }
  51.    
  52.     return max;
  53. }
  54.  
  55. long int P4Factorial( long int a )
  56. {
  57.      if( a == 1 || a == -1 )
  58.          return 1;
  59.      
  60.      if( a < 0 )
  61.          return a * P4Factorial( a + 1 );
  62.      
  63.      return a * P4Factorial( a - 1 );
  64. }
  65.  
  66. long int P4Pow( int n, int e )
  67. {
  68.      if( e <= 0 )
  69.          return 1;
  70.          
  71.      if( e == 1 )
  72.          return n;
  73.          
  74.      return n * P4Pow( n, e - 1 );
  75. }
  76.  
  77. float P4AproxSqrt( float num, int iters )
  78. {
  79.       if( num == 0 || num < 0 )
  80.           return 0;
  81.          
  82.       float sqrt, q = num / 2;
  83.      
  84.       for( int i = 0; i < iters; i++ )
  85.       {
  86.            sqrt = ( q + num / q ) / 2;
  87.            
  88.            q = sqrt;
  89.       }
  90.      
  91.       return sqrt;
  92. }


Comments

POSTED BY: bigner ON 0000-00-00 00:00:00
at least i got it Tnx u for code

You must be logged in to post comments.

 Network Access...
USER ID
PASSWORD

 Code Information
Language:
C/C++

Version:



Submitted:
2008-10-12 - 16:48:42


Author:
p4ll4t0n
E-Mail
Website

Greetz:


[ Download | Report Issue ]

 Code Search
Search by Language
+ Assembly
+ ASP
+ ASP.NET
+ C#
+ C/C++
+ Cobol
+ Delphi
+ Java
+ Javascript
+ Pascal
+ Perl
+ PHP
+ Python
+ VB6
+ VB.NET

Advanced Search




 
By continuing past this page, and by your continued use of this site, you agree to be bound by and abide by the User Agreement.

© 2008 r00tsecurity network. All rights reserved.
[ About Us | Contact Us | Support Us | Legal | Advertise | User Agreement | Privacy Policy ]