ceil

Implementation of ceil function in C

南笙酒味 提交于 2019-11-28 01:35:21
问题 I have two questions regarding ceil() function.. The ceil() function is implemented in C. If I use ceil(3/2) , it works fine. But when I use ceil(count/2) , if value of count is 3, then it gives compile time error. /tmp/ccA4Yj7p.o(.text+0x364): In function FrontBackSplit': : undefined reference to ceil' collect2: ld returned 1 exit status How to use the ceil function in second case? Please suggest. How can I implement my own ceil function in C. Please give some basic guidelines. Thanks. 回答1:

Python - Ceil a datetime to next quarter of an hour

旧时模样 提交于 2019-11-27 21:17:36
Let's imagine this datetime >>> import datetime >>> dt = datetime.datetime(2012, 10, 25, 17, 32, 16) I'd like to ceil it to the next quarter of hour, in order to get datetime.datetime(2012, 10, 25, 17, 45) I imagine something like >>> quarter = datetime.timedelta(minutes=15) >>> import math >>> ceiled_dt = math.ceil(dt / quarter) * quarter But of course this does not work This one takes microseconds into account! import math def ceil_dt(dt): # how many secs have passed this hour nsecs = dt.minute*60 + dt.second + dt.microsecond*1e-6 # number of seconds to next quarter hour mark # Non-analytic

Round up a CGFloat in Swift

一个人想着一个人 提交于 2019-11-27 18:26:38
How can I round up a CGFloat in Swift? I've tried ceil(CDouble(myCGFloat)) but that only works on iPad Air & iPhone 5S. When running on another simulated device I get an error saying 'NSNumber' is not a subtype of 'CGFloat' Update : Apple have now defined some CGFloat-specific versions of common functions like ceil : func ceil(x: CGFloat) -> CGFloat ...specifically to cope with the 32/64-bit difference. If you simply use ceil with a CGFloat argument it should now work on all architectures. My original answer: This is pretty horrible, I think, but can anyone think of a better way? #if doesn't

How can I make sure a float will always be rounded up with PHP?

巧了我就是萌 提交于 2019-11-27 14:26:00
问题 I want to make sure a float in PHP is rounded up if any decimal is present, without worrying about mathematical rounding rules. This function would work as follows: 1.1 to 2 1.2 to 2 1.9 to 2 2.3 to 3 2.8 to 3 I know the round() function exists but I don't see any function for rounding up if any decimal is found. Is there any easy way to do this? 回答1: Use the ceil function: $number = ceil(1.1); //2 回答2: I know this is an old topic, however it appears in Google. I will extend Blake Plumb's

Round minutes to ceiling using Java 8

匆匆过客 提交于 2019-11-27 13:41:37
问题 So I'm lucky enough to use Java 8 and the new time APi but I don't see any rounding functions... Basically if the time is... 2014-08-28T10:01.00.000 ----> 2014-08-28T10:02.00.000 2014-08-28T10:01.10.123 ----> 2014-08-28T10:02.00.000 2014-08-28T10:01.25.123 ----> 2014-08-28T10:02.00.000 2014-08-28T10:01.49.123 ----> 2014-08-28T10:02.00.000 2014-08-28T10:01.59.999 ----> 2014-08-28T10:02.00.000 This seems to be ok, but is it right? LocalDateTime now = LocalDateTime.now(Clock.systemUTC());

html+js+css 实现满天星

馋奶兔 提交于 2019-11-27 11:11:43
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>满天星</title> <style> *{ margin: 0; padding: 0; } html,body { width: 100%; height: 100%; background-color: black; position: relative; } .star-animation { position: relative; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; } /*动画设计*/ @-webkit-keyframes identifier { 25% { transform: scale(1.5); } 50% { transform: scale(2); } 75% { transform: scale(1.5); } 100% { transform: scale(1); } } @-o-keyframes identifier { 25% { transform: scale(1.5); } 50% { transform: scale(2); } 75% { transform: scale(1.5); } 100% {

Get ceiling integer from number in linux (BASH)

微笑、不失礼 提交于 2019-11-27 07:46:37
How would I do something like: ceiling(N/500) N representing a number. But in a linux Bash script Call out to a scripting language with a ceil function. Given $NUMBER : python -c "from math import ceil; print ceil($NUMBER/500.0)" or perl -w -e "use POSIX; print ceil($NUMBER/500.0), qq{\n}" Why use external script languages? You get floor by default. To get ceil, do $ divide=8; by=3; let result=($divide+$by-1)/$by; echo $result 3 $ divide=9; by=3; let result=($divide+$by-1)/$by; echo $result 3 $ divide=10; by=3; let result=($divide+$by-1)/$by; echo $result 4 $ divide=11; by=3; let result=(

Rounding to nearest fraction (half, quarter, etc.)

被刻印的时光 ゝ 提交于 2019-11-27 03:39:51
So, I need to create the following functions but my head can't think of any possibility in PHP without complicated math. Round always up to the nearest decimal (1.81 = 1.90, 1.89 = 1.90, 1.85 = 1.90) Round always down to the nearest decimal (1.81 = 1.80, 1.89 = 1.80, 1.85 = 1.80) Round always up to the nearest x.25 / x.50 / x.75 / x.00 (1.81 = 2, 1.32 = 1.50) Round always down to the nearest x.25 / x.50 / x.75 / x.00 (1.81 = 1.75, 1.32 = 1.25) Round always up to the nearest x.50 / 1 (1.23 = 1.50, 1.83 = 2) Round always down to the nearest x.50 / 1 (1.23 = 1, 1.83 = 1.50) I have searched on

Ceiling of a number in JSTL/EL

亡梦爱人 提交于 2019-11-27 02:16:36
问题 In JSTL, <fmt:formatNumber value="${1.6}" type="number" pattern="#"/> returns 2 and the following <fmt:formatNumber value="${1.4}" type="number" pattern="#"/> returns 1 and I need 2 , a ceiling of a number . Is there a direct way to achieve this in JSTL (or the only way to do so is by using an appropriate custom tag)? 回答1: The default rounding mode of DecimalFormat that is used by <fmt:formatNumber> is RoundingMode.HALF_EVEN. There is no way to change that via any tag attribute. Just add 0.5