Channels

#random

Title

# random

c

Colton Idle

11/30/2023, 3:26 PMSo apparently i cant math. I'm doing some stuff where I have 1 second to the pow of 5. That equals 1. but now i need ms instead of sec. and 1000 ^ 5 is like 100000000000000. do I need to divide the pow by like 1000 or something? lol. maybe i need sleep.

s

Shawn

11/30/2023, 3:31 PMWhat do you mean by having "1 second to the pow of 5"?

are you describing a function that takes

`n`

seconds and raises it to the fifth power?c

Colton Idle

11/30/2023, 3:35 PMyeah. i have a function that takes n seconds and raises it to the fifth power. everything works fine with it. and all expected cases (like 1 second) to the fifth power, should equal 1. but now i need to convert to mills so if I take in 1000 millis, i still need 1000 as the output of the func

s

Shawn

11/30/2023, 3:39 PMI guess you could convert to a BigDecimal, divide by 1000 to convert to seconds, do your arithmetic with seconds as normal, and then multiply by 1000 and convert to an int to yield milliseconds

there's potential for loss in precision in that process though, something to keep in mind

kinda seems like overkill though, depending on what *exactly* you need

c

Colton Idle

11/30/2023, 3:41 PM`int to yeild`

whats that mean?precision isn't too important. but it has to be in the ballpark

s

Shawn

11/30/2023, 3:42 PMI mean "multiply your BigDecimal by 1000 and convert it back to an

`Int`

in order to yield `milliseconds`"➕ 1

c

Colton Idle

11/30/2023, 3:42 PMgotcha. alright. let me try to see what i can come up with.

i think my issue will be that something like the result of 0.5 to the power of 5 is not what i want. but 500ms to the power of 5 also is'nt what i want. hmm

who knew taking an existing func that deals with seconds and converting to millis would give me a headache. lol

s

Shawn

11/30/2023, 3:44 PMhmm, true

I think typically you'd write the method for milliseconds first and then do conversions to accept seconds lol

c

Colton Idle

11/30/2023, 3:45 PMmy contraint here is basically i have tests already written and so they cant break. they already verify that the inputs and outputs (currently in seconds) are what they should be.

r

Ruckus

11/30/2023, 4:00 PMThat's because your base assumption is wrong.

`(1 s)^5`

is not `1 s`

, it's `1 s^5`

(one "five dimensional second"), and `1 s^5`

is not `1_000 ms^5`

, it's `1_000_000_000_000_000 ms^5`

(`1_000^5 ms^5`

). (Just like a unit cube is made of 8 half unit cubes, not 2.)🤯 1

➕ 2

Always remember that units are not just pretty decorations for numbers.

🤔 1

➕ 2

k

Klitos Kyriacou

11/30/2023, 5:25 PMA typical example: 1 cubic metre = 1,000,000 cubic centimetres.
1 m³ = 100³ cm³
Note how the power applies to the units too.
But...
What on Earth does seconds to the power of 5 represent? It sounds very fishy. How can that possibly be useful?

👆 1

c

Colton Idle

11/30/2023, 6:15 PMI wish I knew **@Klitos Kyriacou** lol
I'm just picking up from an existing codebase. But this convo at least made me realize I wasn't going crazy and missing something simple. Thanks everyone. Glad I asked the question

r

Ruckus

11/30/2023, 6:19 PMIt's worth pointing out, that's one of the reasons things like time complexity are base on unit-less

`n`

(e.g. `O(n^2)`

) and not on the time it takes `n`

to happen. That way the end result is also unit-less (as opposed to `time^2`

in this case), and things like nested loops can still take place in one dimensional time.`n`

operation takes `s`

seconds to complete, so if we have a calculation that does that `n`

operations in 5 nested loops, how long will it take?" you should be calculating `n^5`

, not `s^5`

. If all they give you is `s`

, you need to factor out time to get to `n`

before doing the calculation.m

Marcin Wisniowski

01/11/2024, 3:22 PMWhat on Earth does seconds to the power of 5 represent?1m/s = I moved 1 meter in a second 1m/s^2 = Every second I increased my movement speed by 1m/s 1m/s^3 = Every second I increased my acceleration rate by 1m/s^2 1m/s^4 = Every second I increased the rate of increase of my acceleration by 1m/s^3 1m/s^5 = Every second I increased the rate of increase of the rate of increase of my acceleration by 1m/s^4

Far fetched when you get to ^5, but not unreal.

👍 1

c

Colton Idle

01/11/2024, 4:41 PMLol. I wish I knew. I didn't write this. I just got the instructions to change it.