infinity

Infinite integer in Python

倖福魔咒の 提交于 2019-12-05 08:22:17
问题 Python 3 has float('inf') and Decimal('Infinity') but no int('inf') . So, why a number representing the infinite set of integers is missing in the language? Is int('inf') unreasonable? 回答1: Taken from here: https://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number) That is, the representation of float and Decimal can store these special values. However, there is nothing within the

Why does the use of integer variables throw an exception?

允我心安 提交于 2019-12-05 05:47:59
I have come across with the following two codes. Why does it not throw an exception for floating point where as in other case it will throw a runtime exception. class FloatingPoint { public static void main(String [] args) { float a=1000f; float b=a/0; System.out.println("b=" +b); } } OUTPUT:b=Infinity . If I try with int values then it will throw a runtime exception. Why is it like this? polygenelubricants The short answer Integral types ( JLS 4.2.1 ) are categorically different from floating point types ( JLS 4.2.3 ). There may be similarities in behavior and operations, but there are also

Infinity in MSVC++

风流意气都作罢 提交于 2019-12-05 04:04:22
I'm using MSVC++, and I want to use the special value INFINITY in my code. What's the byte pattern or constant to use in MSVC++ for infinity? Why does 1.0f/0.0f appear to have the value 0? #include <stdio.h> #include <limits.h> int main() { float zero = 0.0f ; float inf = 1.0f/zero ; printf( "%f\n", inf ) ; // 1.#INF00 printf( "%x\n", inf ) ; // why is this 0? printf( "%f\n", zero ) ; // 0.000000 printf( "%x\n", zero ) ; // 0 } Use numeric_limits : #include <limits> float maxFloat = std::numeric_limits<float>::infinity(); peterchen printf("%x\n", inf) expects an integer (32 bit on MSVC), but

How to represent integer infinity?

限于喜欢 提交于 2019-12-04 23:50:44
I need a way to represent an integer number that can be infinite. I'd prefer not to use a floating point type (double.PositiveInfinity) since the number can never be fractional and this might make the API confusing. What is the best way to do this? Edit: One idea I haven't seen yet is using int? with null representing infinity. Are there any good reasons not to do this? If you don't need the full range of integer values, you can use the int.MaxValue and int.MinValue constants to represent infinities. However, if the full range of values is required, I'd suggest either creating a wrapper class

Why are floating point infinities, unlike NaNs, equal?

这一生的挚爱 提交于 2019-12-04 09:50:21
问题 Why doesn't infinity comparison follow the logic applied to NaNs? This code prints out false three times: double a = Double.NaN; double b = Double.NaN; System.out.println(a == b); // false System.out.println(a < b); // false System.out.println(a > b); // false However, if I change Double.NaN to Double.POSITIVE_INFINITY , I get true for equality, but false for the greater-than and less-than comparisons: double a = Double.POSITIVE_INFINITY; double b = Double.POSITIVE_INFINITY; System.out

Meteor template reload infinity

佐手、 提交于 2019-12-04 06:49:34
I have a problem when running with Meteor. I have a "question" page which I want to increase the count view whenever it is rendered. So in my template function I write Template.questionview.helpers({ question : function() { if(Session.equals('main_template_name', 'question')) { console.log(Session.get('question_id')); Questions.update({ _id: Session.get('question_id') }, { $inc: { views: 1 } }); } }); Now here comes the problem, when I render the question view and update the question item, the view is refreshed again because it is a reflective page. And then it comes infinity loop. Anyone has

How to produce infinity in Haskell?

戏子无情 提交于 2019-12-04 04:28:31
问题 Similarily to How to produce a NaN in Haskell ... In C, there is the INFINITY macro, defined by math.h . Again, in http://hackage.haskell.org/package/ClassyPrelude-0.1/docs/Prelude-Math.html I can see falicities to test for infnity, but not to produce one. Therefore, is my only choice something like 1/0 ? 回答1: The iee754 package has functions and constants specific to that floating point format. In particular, it has the Numeric.IEEE.infinity constant for members for the IEEE class (which

Is there any way to programmatically set the camera focus off an iOS device to infinity?

送分小仙女□ 提交于 2019-12-03 11:58:16
问题 I am creating an app that locks the camera focus for video recording purposes. I want to lock the focus to infinity without having the user manually adjust the focus. Is this possible? Thanks! 回答1: That is the way to disable focus, it locks it for all the time: // Find a suitable capture device AVCaptureDevice *cameraDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; // SETUP FOCUS MODE if ([cameraDevice lockForConfiguration:nil]) { [cameraDevice setFocusMode

In gnuplot, with “set datafile missing”, how to ignore both “nan” and “-nan”?

爷,独闯天下 提交于 2019-12-03 07:47:40
The gnuplot command set datafile missing "nan" tells gnuplot to ignore nan data values in the data file. How to ignore both nan and -nan ? I tried the following in gnuplot, but then the effect of the first statement is overwritten by the next. gnuplot> set datafile missing "-nan" gnuplot> set datafile missing "nan" Is it possible to somewhow embed a grep -v nan in the gnuplot command, or even some kind of regexp to exclude any imaginable non-numerical data? Christoph It is not possible to use a regexp for set datafile missing , but you can use any program to filter you data before plotting,

Why are floating point infinities, unlike NaNs, equal?

≡放荡痞女 提交于 2019-12-03 04:09:56
Why doesn't infinity comparison follow the logic applied to NaNs? This code prints out false three times: double a = Double.NaN; double b = Double.NaN; System.out.println(a == b); // false System.out.println(a < b); // false System.out.println(a > b); // false However, if I change Double.NaN to Double.POSITIVE_INFINITY , I get true for equality, but false for the greater-than and less-than comparisons: double a = Double.POSITIVE_INFINITY; double b = Double.POSITIVE_INFINITY; System.out.println(a == b); // true System.out.println(a < b); // false System.out.println(a > b); // false This seems