Originally Posted by
gawiellus
You can't use any of the characters +-*/%&|^~<>#? in your code, which means:
- You can't do any arithmetic/bitwise operations.
- You can't do any pointer/address operations.
- You can't include any extra files.
Actually, there is one solution, but it isn't pretty and match all the requirements. You are doing arithmetic and logical instructions, but not in C!
You can use assembly (not inline assembly, because you will have to use % for this). So, using NASM you can:
Code:
// test.c
extern int getexp( double );
int main( void )
{
// test value
double d = 3.14;
// this is the single line of code using '%' char
// you can create your own itoa() function to overcome this this way:
//
// char buff[8];
// int n = getexp( d );
// itoa( buff, n );
// fputs( "exp = ", stdout );
// puts( buff );
printf( "exp = %d\n", getexp( d ) );
}
Code:
; getexp.asm
bits 64
default rel
section .text
global getexp
getexp:
movq rax,xmm0
shr rax,52
and eax,0x7ff
sub eax,1023
ret
Compile and run with:
Code:
$ cc -include stdio.h -c -o test.o test.c
$ nasm -felf64 -o getexp.o getexp.asm
$ cc -o test test.o getexp.o
$ ./test
1