When I divide numbers in clojure i get a fraction , how do I get the decimal?
When i do (/ 411 125) , i dont get it in terms of decimal, how do I do that? ...
When i do (/ 411 125) , i dont get it in terms of decimal, how do I do that? ...
Hey all, let's jump straight to a code sample to show how ECMAScript/JavaScript/AS3 can't do simple math right (AS3 uses a 'IEEE-754 double-precision floating-point number' for the Number class which is supposedly identical to that used in JavaScript)... trace(1.1); //'1.1': Ok, fine, looks good. trace(1.1*100); //'110.00000...
At some point in an algorithm I need to compare the float value of a property of a class to a float. So I do this: if (self.scroller.currentValue <= 0.1) { } where currentValue is a float property. However, when I have equality and self.scroller.currentValue = 0.1 the if statement is not fulfilled and the code not executed! I found o...
I was out looking for the rounding convention used by Perl's built-in function sprintf. I was thinking that it does a normal rounding (e.g. ROUND_HALF_UP as in Java's rounding mode convention), but digging further proved this to be wrong: > /usr/local/bin/perl5.10.1 -e 'print(sprintf("%.2f", shift @ARGV)."\n");' 0.335 0.34 > /usr/local...
How can I write an algorithm that given a floating point number, and attempts to represent is as accurately as possible using a numerator and a denominator, both restricted to the range of a Java byte? The reason for this is that an I2C device wants a numerator and denominator, while it would make sense to give it a float. For example,...
Well, I'm a beginner, it's my year as a computer science major. I'm trying to do an exercise from my textbook that has me use a struct called MovieData that has a constructor that allows me to initialize the member variables when the MovieData struct is created. Here's what my code looks like: #include <iostream> #include <iomanip> #i...
Hello I need to do some floating point arithmetic in java as shown in the code below: public class TestMain { private static Map<Integer, Double> ccc = new HashMap<Integer, Double>() { { put(1, 0.01); put(2, 0.02); put(3, 0.05); put(4, 0.1); put(6, 0.2); put(10, 0.5); put(20, 1.0); pu...
So, we know that fractions such as 0.1, cannot be accurately represented in binary base, which cause precise problems (such as mentioned here: http://stackoverflow.com/questions/1421520/formatting-doubles-for-output-in-c). And we know we have the decimal type for a decimal representation of numbers... but the problem is, a lot of Math m...
Refreshing on floating points (also PDF), IEEE-754 and taking part in this discussion on floating point rounding when converting to strings, brought me to tinker: how can I get the maximum and minimum value for a given floating point number whose binary representations are equal. Disclaimer: for this discussion, I like to stick to 32 bi...
Hi i have to read a flot value from string up to 6 precision , Current code is reading first 6 digits only. Thanks in Advance template <class T> bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) { std::istringstream iss(s); return !(iss >> f >> t).fail(); } int main() { int i...
What is the smallest exact representation of 1/(2^x) that can be represented in the C programming language? ...
Possible Duplicates: Strange problem comparing floats in objective-C Is JavaScripts math broken? 1.265 * 10000 = 126499.99999999999 ????? After watching this I discovered that in JavaScript: 0.1 + 0.2 === 0.3 evaluates to false. Is there a way to work around this? ...
Yesterday I asked a floating point question, and I have another one. I am doing some computations where I use the results of the math.h (C language) sine, cosine and tangent functions. One of the developers muttered that you have to be careful of the return values of these functions and I should not make assumptions on the return values...
I am trying to print out each bit of a floating point number in c. I can be able to do it for integer with this: int bit_return(int a, int loc) // bit returned at location { int buf = a & 1<<loc; if (buf == 0) return 0; else return 1; } the compiler wouldn't compile if I replace int a with float a. Does anybody have ...
I have an immutable Vector3 structure, and I'm wondering how to best implement the .Equals() method so that it's useful and still satisfies the Guidelines for Overloading Equals(). Here's a partial implementation of my structure: public struct Vector3 { private float _x; private float _y; private float _z; public flo...
When I convert an unsigned 8-bit int to string then I know the result will always be at most 3 chars (for 255) and for an signed 8-bit int we need 4 chars for e.g. "-128". Now what I'm actually wondering is the same thing for floating-point values. What is the maximum number of chars required to represent any "double" or "float" value a...
I'm working on some functionality in a financial application. All numbers are represented as decimals without rounding errors both in the code and in the database. However, I'm having some performance problems and I'm considering switching to floating point numbers (float/double) in my own computations. This is based on the assumption th...
Are there any lower bounds for floating point types in C? Like there are lower bounds for integral types (int being at least 16 bits)? ...
i tried this: float a = 1.4123; a = a & (1 << 3); i get a compiler error saying that operand to & cannot be of type float. when i do: float a = 1.4123; a = (int)a & (1 << 3); i get the program running. only thing is that the bitwise operation is done on the integer representation of the number obtained after rounding off. float a...
I was looking at the implementation of compare(double, double) in the Java standard library (6). It reads: public static int compare(double d1, double d2) { if (d1 < d2) return -1; // Neither val is NaN, thisVal is smaller if (d1 > d2) return 1; // Neither val is NaN, thisVal is larger long thisBits =...