How to check if a big number is a square of an integer in R?

Vassilis Chasiotis

I want to check if the determinant of a 22x22 matrix is a square of an integer or not.

So I have

> det(M)
[1] 1.849688e+29
> sqrt(det(M))
[1] 4.3008e+14

But now I can't see the decimal digits of this number.

So, if I run

> options(digits=22)
> sqrt(det(M)) 
[1] 430080000000001.1875000

I have this result, which means that it isn't square of an integer.

So, when I use the following function

check.integer <- function(N){
    !length(grep("[^[:digit:]]", as.character(N)))
}

the result is that the number is an integer.

Neil

Your check.integer function does not really check if something is an integer. It checks if whatever R's character representation of something happens to have a non-digit character in it. This is a pretty bad way of doing things. You want to know if something really is and integer and not just if it looks like one.

Besides, there is already the is.integer function in R.

But this may not help in your case. R will only exactly represent integers up to a certain point, which is one of the many things stored in .Machine. In particular:

.Machine$integer.max

If you want to check if a matrix determinant that may be larger than .Machine$integer.max is a square in R you can consider going to arbitrary precision. The Rmpfr package should be able to do all this for you. It lets you have arbitrary precision matrices, has its own determinant function, and has its own is.whole function.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to check if an integer is a perfect square

From Dev

How to check if a number is a perfect square by using mpfr package in R?

From Dev

How to find the square root of a big integer in R language? (package gmp doesn't have sqrt for bigz)

From Dev

How to check if number is integer number, with good precision?

From Java

How do I check that a number is float or integer?

From Dev

C - How to check if the number is integer or float?

From Dev

Twig - How to check if variable is a number / integer

From Dev

Big Integer looping number calculation

From Dev

Check if number is of Integer type

From Dev

Check if number is of Integer type

From Dev

How big is an Integer() in Java?

From Java

How can I check, the number that scanner received is an integer certainly in java?

From Dev

How can I check when integer is incremented beyond a multiple of a number?

From Dev

How to check if a number (float or integer) is within a range (0 - 100)

From Dev

How can I check when integer is incremented beyond a multiple of a number?

From Dev

how to check if the number is not an integer in C without using isdigit?

From Dev

Check if a number is an integer or non-integer rational

From Dev

Check if a number is an integer with basic arithmetic

From Dev

How to check for big files?

From Dev

How to compute a check digit for a large number in R?

From Dev

How to compute a check digit for a large number in R?

From Dev

How to check if a variable is an integer?

From Dev

How to check if a variable is an integer?

From Dev

How to check if divided number is integer and how to take out of symbols row in Delphi?

From Dev

Regular expression to check for integer or decimal number in iOS

From Dev

Check if variable is a number and positive integer in PHP?

From Dev

Check integer number is between two values

From Dev

How to replace the number with forward slash to square square brackets in python

From Dev

How Do I Get An EditText To Check If It Equals Any Number In A Integer ArrayList?

Related Related

  1. 1

    How to check if an integer is a perfect square

  2. 2

    How to check if a number is a perfect square by using mpfr package in R?

  3. 3

    How to find the square root of a big integer in R language? (package gmp doesn't have sqrt for bigz)

  4. 4

    How to check if number is integer number, with good precision?

  5. 5

    How do I check that a number is float or integer?

  6. 6

    C - How to check if the number is integer or float?

  7. 7

    Twig - How to check if variable is a number / integer

  8. 8

    Big Integer looping number calculation

  9. 9

    Check if number is of Integer type

  10. 10

    Check if number is of Integer type

  11. 11

    How big is an Integer() in Java?

  12. 12

    How can I check, the number that scanner received is an integer certainly in java?

  13. 13

    How can I check when integer is incremented beyond a multiple of a number?

  14. 14

    How to check if a number (float or integer) is within a range (0 - 100)

  15. 15

    How can I check when integer is incremented beyond a multiple of a number?

  16. 16

    how to check if the number is not an integer in C without using isdigit?

  17. 17

    Check if a number is an integer or non-integer rational

  18. 18

    Check if a number is an integer with basic arithmetic

  19. 19

    How to check for big files?

  20. 20

    How to compute a check digit for a large number in R?

  21. 21

    How to compute a check digit for a large number in R?

  22. 22

    How to check if a variable is an integer?

  23. 23

    How to check if a variable is an integer?

  24. 24

    How to check if divided number is integer and how to take out of symbols row in Delphi?

  25. 25

    Regular expression to check for integer or decimal number in iOS

  26. 26

    Check if variable is a number and positive integer in PHP?

  27. 27

    Check integer number is between two values

  28. 28

    How to replace the number with forward slash to square square brackets in python

  29. 29

    How Do I Get An EditText To Check If It Equals Any Number In A Integer ArrayList?

HotTag

Archive