I found myself needing to compute the “integer cube root”, meaning the cube root of an integer, rounded down to the nearest integer. In Python, we could use the NumPy floating-point cbrt() function: Though this works most of the time, it fails at certain input x, with the result being one less than expected. For example, icbrt(15**3) == 14, which
Tag: floating-point
How many times can you divide 24**36 by 2 until it becomes imprecise?
How many times can you divide 24**36 by 2 until it becomes imprecise? I had this question on one of my quizzes in a python course, and I’m curious as to what the correct answer is. (It’s already submitted so no cheating here) I wrote this small bit of code in python to calculate how many times you can evenly
How to disable python rounding?
I’m looking for a way to disable this: print(0+1e-20) returns 1e-20, but print(1+1e-20) returns 1.0 I want it to return something like 1+1e-20. I need it because of this problem: returns f1 is the original function, f2 is f1 shifted by 1 to the left and f3 is f2 moved back by 1 to the right. By this logic, f1
Exctract a value from a Json file(python)
Hi i’m not an expert and this problem kept me stuck for such a long time I hope that someone here can help me i would like to exctract the value “interestExpense” from the following json file: In this case the result should be -130000000 as a string but i m trying to find a way to create an list(or
Multiple data types in a python list
I have a list for birth data each record has 3 columns for [DOB, weight, height] as such: bd = [[’10/03/2021 00:00′,’6.2′, ‘33.3’],[’12/04/2021 00:00′,’6.2′, ‘33.3’], [’13/05/…
Why do I lose numerical precision when extracting element from list in python?
I have a pandas dataframe that looks like this: data 0 [26.113017616106, 106.948066803935, 215.488217… 1 [26.369709448639, 106.961107298101, 215.558911… 2 [26….
It doesn’t append as floating Python | Problem #18
I’m writing this code for the problem #18 in Codeabbey. I need to calculate the square root of an array of numbers [150, 0, 5, 1 10, 3] I have to divide this array in three arrays (x,n) [[150, 0], [5, …
How is floor division not giving result according to the documented rule?
>>> print (12//0.2) 59.0 >>> print(floor(12/0.2)) 60 Why floor division is not working according to the rule in this case? p.s. Here Python is treating 0.2 as 0.20000000001 in the …
How do I get the user to input an int rather than a float?
I’m writing a program that takes in a value from the user, in the console, and I’m casting it to an int like so: num = int(input(“Enter a number: “)) I need my program to work with ints only. This …
Explicitly Define Datatype in Python Function
I want to define 2 variables in python function and define them as float explicitly. However, when i tried to define them in the function parameter, it’s showing syntax error. Please help me get the …