I am currently designing and implementing a small programming language as an extra-credit project in a class I'm taking. My problem is that the language has three numeric types: Long, Double, and Fraction. Fractions can be written in the language as proper or improper fractions (e.g. "2 1/3" or "1/2"). This fact leads to problems such as...
I am working on the firmware for a device that uses an 8bit mcu (8051 architecture). I am using SDCC (Small Device C Compiler). I have a function that I use to set the speed of a stepper motor that my circuit is driving. The speed is set by loading a desired value into the reload register for a timer. I have a variable, MotorSpeed that ...
I thought java.math.BigDecimal is supposed to be The Answer to the need of performing infinite precision arithmetic with decimal numbers.
Consider the following snippet:
import java.math.BigDecimal;
//...
final BigDecimal one = BigDecimal.ONE;
final BigDecimal three = BigDecimal.valueOf(3);
final BigDecimal third = one.divide(three);
...
How can i multiply and divide with only using bit shifting and adding?
...
Hay i need help.
I want to find all muliples of a number in PHP.
I'm using something like this
if($count != 20 )
to work out if $count is not equal to 20.
but i also need this script to check if $count is not equal to 20,40,60,80,100,120,140,160 etc.
Any ideas? I think i need to use the modulus symbol (%), but i don't know.
Thank...
In the spirit of using existing, tested and stable libraries of code, I started using the Apache-Commons-Math library and its BigFraction class to perform some rational calculations for an Android app I'm writing called RationalCalc.
It works great for every task that I have thrown at it, except for one nagging problem. When dividing c...
Possible Duplicates:
Is long x = 1/2 equal to 1 or 0, and why?
C# and Java : 3 / 2 * 3.2 = 3.2, why??
Hello,
Im astonished. Im trying this simple calculation in a Java application:
System.out.println("b=" + (1
- 7/10));
Obviously Im wainting for "b=0.3" in the output but here's what I get:
b=1
What?! Why this ...
Running the following C# code through NUnit yields
Test.ControllerTest.TestSanity: Expected: `<System.DivideByZeroException>` But was: null
So either no DivideByZeroException is thrown, or NUnit does not catch it. Similar to this question, but the answers he got, do not seem to work for me. This is using NUnit 2.5.5.10112, and .NET ...
If I want to check that positive float A is less than the inverse square of another positive float B (in C99), could something go wrong if B is very small?
I could imagine checking it like
if(A<1/(B*B))
but if B is small enough, would this possibly result in infinity? If that were to happen, would the code still work correctly in al...
Hi, the following query
CREATE TABLE IF NOT EXISTS XY (
x INT NOT NULL ,
y FLOAT NULL ,
PRIMARY KEY(x)
)
INSERT INTO XY (x,y)
(select 1 as x ,(1/7) as y);
errors with
Error code 1064, SQL state 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use ne...
Guys I'm working on class called LINT (large int) for learning purposes, and everything went ok till know. I'm stuck on implementing operator/(const LINT&). The problem here is that in when I want to divide LINT by LINT I'm getting into recursive fnc invocation i.e:
//unfinished
LINT_rep LINT_rep::divide_(const LINT_rep& bottom)const
{...
Hi all,
I just write a procedure to decompose an unsigned integer to prime numbers. it will work normally if I define the data type as "int", if I change it to "long", result will be wrong. I don't know why.
BTW, I used Win-TC as my compiler.
Code as below:
#include "stdio.h"
#define True 0xff
#define False 0x00
char DividerIsPr...
Hi,
I'm trying to implement long division for bignums. I can't use a library like GMP unfortunately due to the limitations of embedded programming. Besides, i want the intellectual exercise of learning how to implement it. So far i've got addition and multiplication done using any-length arrays of bytes (so each byte is like a base-256 d...
I'm having an issue trying to divide two decimals and then display the result. Annoyingly this is only happening on our server, and it appears to work perfectly fine if I run the code locally. This is the code that I am trying to run
decimal dOne = -966.96M;
decimal dTwo = 2300M;
decimal dResult = Decimal.Round((dOne / dTwo), 28,
...
I have come across this problem in a calculation I do in my code, where the divisor is 0 if the divident is 0 too. In my code I return 0 for that case. I am wondering, while division by zero is generally undefined, why not make an exception for this case? My understanding why division by zero is undefined is basically that it cannot be r...
Not sure if it's a duplicate. But I need to find whether a number is divisible by 3 without using %, / or *. The hint given was to use atoi() function. Any idea how to do it?
...
I am looking for a fast way to perform the following divison:
Dividend is a signed 64 bit integer.
Divisor is a signed 32 bit integer.
Quotient should be a signed 64 bit integer, remainder is unnecessary.
Low dword of the dividend is zero.
I am using only 32 bit data types, since 64 bit ones are poorly supported by the compiler, and ...
I've been programming for a while in C++, but suddenly had a doubt and wanted to clarify with the Stackoverflow community.
When an integer is divided by another integer, we all know the result is an integer and like wise, a float divided by float is also a float.
But who is responsible for providing this result? Is it the compiler or D...
I am facing the problem while dividing
my max_sum = 14
total_no=4
so when i do
print "x :", (total_sum/total_no)
, I get 3 and not 3.5
I tried many ways for printing but failed, can somebody let me know what way I get in 3.5 format?
Thank you
...
Possible Duplicates:
Ints and Doubles doing division
1/252 = 0 in c#?
Hi,
Maybe because it's Friday, but I cannot understand this:
(Double)1/2 = 0.5
(Double)1/(Double)2 = 0.5
(Double)((Double)1/(Double)2) = 0.5
(Double)(1/2) = 0.0
Why the last operation is 0? :S
Kind regards.
...