Doubt regarding problem EOEO from June2020B

Problem Code: EOEO
Link: https://www.codechef.com/JUNE20B/problems/EOEO

Why does the following code results in AC for both constraints

import java.util.*;
import java.io.*;
import java.lang.Math;
public class Codechef {
    static Scanner scn = new Scanner(System.in);
    public static void main(String[] args) {
        // FastScanner scanner = new FastScanner(System.in);
        int t = scn.nextInt();
        while (t-- > 0) {
            long ts = scn.nextLong();
            while (ts % 2 == 0) {
                ts /= 2;
            }
            if(ts <= 1){
                System.out.println(0);
            } else{
                System.out.println(ts/2);
            }        
        }
    }

and the code given below results in AC tiny for the 1st constraint:

import java.util.*;
import java.io.*;
import java.lang.Math;
public class Codechef {
    static Scanner scn = new Scanner(System.in);
    public static void main(String[] args) {
        // FastScanner scanner = new FastScanner(System.in);
        int t = scn.nextInt();
        while (t-- > 0) {
            long ts = scn.nextLong();
            while (ts % 2 == 0) {
                ts /= 2;
            }
            System.out.println((int)Math.floor(ts/2));
        }
    }

I’m essentially “flooring” the result in both the snippets, but why do they give different results?

I think it should be (long) Math.floor(ts/2) in the second code

@jay_1048576
But it gave AC without changing that line. The only lines concerned are

//Gave AC
if(ts <= 1){
                System.out.println(0);
            } else{
                System.out.println(ts/2);
            } 
//Doesnt give AC even while typecasting to long
            System.out.println((int)Math.floor(ts/2));

Then it must be due to precision problems of double. Actually you should try to avoid using floating point data types due to their precision problems. For two positive numbers a and b, whenever you need the floor of a/b simply use a/b and when you need the ceil use ((a-1)/b+1)