2
голосов
6ответов
667 просмотров

Why does this division result in zero?

I was writing this code in C when I encountered the following problem. #include <stdio.h> int main() { int i=2; int j=3; int k,l; float a,b; k=i/j*j; l=j/i*i; a=i/j*j; b=j/i*i; printf("%d %d %f %f\n",k,l,a,b); return 0; } Can anyone tell me why the code is r...

4
голосов
6ответов
2876 просмотров

Why is the output of cout <<7/9*9; is zero?

Why is the output of the following code equals to 0 or serven? cout << 7/9*9; //output 0 (zero) why? float nine = 9; float seven = 7; float i = seven/nine*nine; cout << i //output 7 Why? Thanks for the help.

3
голосов
4ответов
2507 просмотров

Avoiding floating point arithmetic

I wrote a small software synth for the iPhone. To further tune performance I measured my application with Shark and found that I am loosing a lot of time in float/SInt16 conversions. So I rewrote some parts to get around the conversions by pre-calculating lookup tables that return "ready-to-use"...

4
голосов
6ответов
1034 просмотров

How do I compute the first decimal digit of a division between large numbers?

I have two unsigned long longs X and Y, where X (X * 10) / Y would work, except it produces the wrong result if X * 10 overflows. Conversion to double would work if I had reason to believe it is precise enough to compute the right result. This is in C. Thanks for any help!

2
голосов
8ответов
9886 просмотров

Поиск целых чисел, которые делятся на 6 или 7, но не на оба

Я пытаюсь написать программу, которая отображает целые числа от 1 до 100, которые делятся на 6 или 7 , но не на оба сразу . Вот мой код: import acm.program.*; public class Problem4 extends ConsoleProgram { public void run() { for (int i = 1; i <= 100; i++) { ...

59
голосов
7ответов
109205 просмотров

Как мне делать целочисленное деление в Perl?

Как лучше всегда выполнять целочисленное деление в Perl? Например, я хочу: real / int = int int / real = int int / int = int