From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 60D171F45A for ; Tue, 13 Aug 2019 16:57:07 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E977E120A0E; Wed, 14 Aug 2019 01:56:58 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 4CAFF120975 for ; Wed, 14 Aug 2019 01:56:56 +0900 (JST) Received: by filter0055p3las1.sendgrid.net with SMTP id filter0055p3las1-22883-5D52EBDA-32 2019-08-13 16:56:58.673180859 +0000 UTC m=+1547424.949701095 Received: from herokuapp.com (unknown [54.224.29.177]) by ismtpd0005p1iad2.sendgrid.net (SG) with ESMTP id UhRiiOPPRoKezpWwHrKSIg for ; Tue, 13 Aug 2019 16:56:58.512 +0000 (UTC) Date: Tue, 13 Aug 2019 16:56:58 +0000 (UTC) From: gabewild37@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 69874 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15609 X-Redmine-Issue-Author: znz X-Redmine-Sender: gabewild37 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?tx8veyuRbg41JbB5EtWbKcOuKrNDwa9Wt86obNMel9JqU5wcNJvFfgNnYjoiQI?= =?us-ascii?Q?gEo=2FOBzHmdvdlcDsDo1upI+pVvRHReG2EGbxdsU?= =?us-ascii?Q?Xwz2mmLqpDm5FVP7VZ9wKG6Z8n=2FnN=2FrksHEb8m4?= =?us-ascii?Q?DZ0oaAQjfsajBAgThsgYfWgyWP9dyLcjFnpRq6s?= =?us-ascii?Q?jIxAXPOvoeXSoQa24NWmQCgk4nU0HvkY+TA=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 94327 Subject: [ruby-core:94327] [Ruby master Feature#15609] Kernel#sleep returns Float instead of Integer X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15609 has been updated by gabewild37 (Gabe Wild). File ruby-changes.patch added Hi, I don't know if anyone still wants this feature, but, since I wanted to get started contributing to ruby, I have implemented the following changes in my patch. Should an integer be entered into the function, the function acts like it used to. Ex: sleep(1) ==> 1, sleep(2) ==> 2. However, should a float be entered instead, the function will return a float. Ex: sleep(1.0) ==> 1.001077, sleep(2.2) ==> 2.202255. I did this by using gettimeofday() instead of time(), so the float returned is accurate to the microsecond. I also added some test code, and updated the documentation I found above the function in process.c to reflect my new changes. However, I think, instead of doing what I did, maybe making a new function or adding an optional flag could be better. Now that the return values are no longer rounded to integers, the changes in my patch could cause some backwards compatibility issues if someone is relying on rb_f_sleep to return an integer. Since I am new to both ruby and open s ource in general, any comments, suggestions, or improvements are appreciated. ---------------------------------------- Feature #15609: Kernel#sleep returns Float instead of Integer https://bugs.ruby-lang.org/issues/15609#change-80715 * Author: znz (Kazuhiro NISHIYAMA) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- `rb_f_sleep` uses `time()` internally, so it always returns Integer even if it called with Float. https://github.com/ruby/ruby/blob/124957566f041e5c6e8f678dfaf62cae381826dc/process.c#L4840-L4857 I think returning Float is more useful than Integer. (But I have no real use cases now.) ---Files-------------------------------- ruby-changes.patch (2.53 KB) -- https://bugs.ruby-lang.org/