Results 1 to 15 of 15

Thread: TAN AND SIN math problem

  1. #1

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461

    TAN AND SIN math problem

    okay. how would i un sin and un tan somting, if i somting , if TAN(2) is 0.034920769491747730500402625773725, how would i get 2 back, same with sin, is this possable?
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    arcsine etc:
    x == acos(cos(x));
    (except for rounding)
    asin/sin
    atan/tan

    Don't forget that those functions work with radians.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    sin, cos and tan are not injective, tan has a periodicity of pi, while sin and cos have 2pi but are symmetric at 1/2*pi + n*pi respective 0+n*2pi. Usually you can find a workaround for full 2*pi angles trough using the euler transformation and atn2, X=atn2(sin(X),cos(X))
    Last edited by kedaman; Dec 17th, 2002 at 08:13 AM.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Huh?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    He's saying - some values are invalid as arguments for arc-whatever functions. The results are undefined.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But the result of a sin, cos or tan is guaranteed to be valid input for asin, acos or atan, respectivly. Except if the input wasn't valid in the first place (e.g. PI/2 to tan).

    But yeah, you're not guaranteed to get out what you put in first. asin(sin(2*PI)) will result in 0.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    im talking about SIN(TAN(y*X^z))
    i want to get y back from knowing X^z
    basicly i want to use it for a weak! encription, however if you know how to make it STRONG using sin,cos, and tan help would be apreciated!...
    Last edited by Cmdr0Sunburn; Dec 17th, 2002 at 05:47 PM.
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The problem, as keda pointed out, lies in the wraparound effect of sin and cos.
    You can find one possible value of (x*y^z), it is
    atan(asin(result))
    but there are infinite possible values (in theory, not for pcs), therefore x is not clearly defined either.

    Trigonometry functions are not a good choice for encryption as they are lossy.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    trigonometric functions are reversible at certain periodic intervals, when playing around with math functions you always have to take into account their domain and range, and if you want an inverse, uniqueness as well. Don't think using floating point functions are useful for encryption, they tend to be inaccurate if you want to reverse them.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    hmm ok well as this code proves that none repeat themselfs i thought i could use it as a encription.
    Code:
    #define ncm 30000000
    void main()
    {
    //SIN(TAN(3*X^3))
    	long double X = 1.0,RESULT = 0,xcubed,Xcubedtried,XTANNED,somewheree,J = 1;
    	unsigned int gtc1 = 0,gtc2 = 0;
    long double* siz = new long double[30080000];//allocate memory
    {
    		int y = 1;
    do
    {
    	J = X;
    	do
    	{
    	xcubed = ((X * X) * X);
    	Xcubedtried = xcubed * (3);
    	XTANNED = tan(Xcubedtried);
    	RESULT = sin(XTANNED);
    	//	if(RESULT == 0)
    	//	{
    	//		std::cout << " 0 FOUND!\n";
    	//		std::cin >> somewheree;
    	//	}
    	//std::cout.precision(24);
    	siz[y] = RESULT;
    
    	X = X + 1.0;
    	y = X;
    	}while(X <J+10000);
    	std::cout  << "#:"<< y << "\n";
    }while(X <= ncm);
    
    }
    	int y = 0,z = 1,repititionc = 0;
    	std::cout << "Input starting #:";std::cin >> y ;
    do
    {
    	std::cout << y <<" Time:"<<(gtc1 - gtc2) <<"\n";
    	gtc2 = GetTickCount();
    
    	z = 1;
    	do {
    	if (siz[y] == siz[z+y])
    	{
    	repititionc++;
    	}
    	//z = z + 1;
    	__asm INC z
    	}while(z <= (ncm - y));
    
    	//y = y + 1;
    	__asm INC y
    		gtc1 = GetTickCount();
    }while(y <= ncm);
    std::cout << "  \n" << repititionc << "\n";
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Are you aware that your code allocates 240 to 300 MB RAM?

    And this:
    __asm INC z
    Why not
    ++z;
    ? It's shorter, easier to read, more portable and the compiler can optimize better.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    yea i have alot of ram hehe,and also i code in assembly(2nd lang and i know more of it than my first and 3rd). Like learning english then moving to spain, then studying german.. as i still think in assembly. i can beat the c++ compiler, i beat 500mhz of a loop in one my program., c++ will almost never use inc wich takes 1 clock and even 2 incs 1 clock on p4s, and 4 incs on 1 clock on amd(thats why amd will always be the best) as add will take more than 1 as if i wanted to add 500, then i could not use inc, so if your doing just adding one or 2, use __asm INC, ~~~ msvc++6 compiler sucks at optimizing.
    Last edited by Cmdr0Sunburn; Dec 18th, 2002 at 04:53 PM.
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    inc only takes that short if executed for the eax register. Same for add.

    But it doesn't really matter. This single statement ensures that your app will not compile on any compiler beside VC++, and not run on any computers except x86. Of course you might not mind.
    The other problems is that no compiler can optimize properly past an asm statement.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    i could code that loop in assembly and i gaurentee that it will be at least 1/3 faster. but i dont want to; this is now a 'junk' project.
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I don't doubt it. But I think that a loop that is one third highly optimized assembly and the other two thirds normal C++ code will be slower than a pure C++ loop because the compiler can't optimize the C++ part properly.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width