ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:91142] [Ruby trunk Bug#15544] sprintf returns an unexpected string
       [not found] <redmine.issue-15544.20190117195220@ruby-lang.org>
@ 2019-01-17 19:52 ` andre.kullmann
  2019-01-17 20:14   ` [ruby-core:91143] " Austin Ziegler
  2019-01-17 22:28 ` [ruby-core:91151] " shevegen
  2019-01-17 22:44 ` [ruby-core:91152] " shyouhei
  2 siblings, 1 reply; 4+ messages in thread
From: andre.kullmann @ 2019-01-17 19:52 UTC (permalink / raw)
  To: ruby-core

Issue #15544 has been reported by areman01 (André Kullmann).

----------------------------------------
Bug #15544: sprintf returns an unexpected string
https://bugs.ruby-lang.org/issues/15544

* Author: areman01 (André Kullmann)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello,

I've a little problem with the sprintf function. It returns unexpected results ( in my opinion )

``` ruby
sprintf("%.16g", 8.78)
# returns "8.779999999999999"
# my expected result is "8.78"
```

Can somebody explain this behavior to me ?

Best Begards



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:91143] Re: [Ruby trunk Bug#15544] sprintf returns an unexpected string
  2019-01-17 19:52 ` [ruby-core:91142] [Ruby trunk Bug#15544] sprintf returns an unexpected string andre.kullmann
@ 2019-01-17 20:14   ` Austin Ziegler
  0 siblings, 0 replies; 4+ messages in thread
From: Austin Ziegler @ 2019-01-17 20:14 UTC (permalink / raw)
  To: Ruby developers


[-- Attachment #1.1: Type: text/plain, Size: 1577 bytes --]

#include <stdio.h>


int main(int argc, char *argv[]) {

  printf("%.16g\n", 8.78);

}


compile and run this and you will get the same result.


The problem is floating-point values cannot be represented in binary
exactly.


https://developers.slashdot.org/story/10/05/02/1427214/what-every-programmer-should-know-about-floating-point-arithmetic


-a

On Thu, Jan 17, 2019 at 2:52 PM <andre.kullmann@googlemail.com> wrote:

> Issue #15544 has been reported by areman01 (André Kullmann).
>
> ----------------------------------------
> Bug #15544: sprintf returns an unexpected string
> https://bugs.ruby-lang.org/issues/15544
>
> * Author: areman01 (André Kullmann)
> * Status: Open
> * Priority: Normal
> * Assignee:
> * Target version:
> * ruby -v: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
> * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
> ----------------------------------------
> Hello,
>
> I've a little problem with the sprintf function. It returns unexpected
> results ( in my opinion )
>
> ``` ruby
> sprintf("%.16g", 8.78)
> # returns "8.779999999999999"
> # my expected result is "8.78"
> ```
>
> Can somebody explain this behavior to me ?
>
> Best Begards
>
>
>
> --
> https://bugs.ruby-lang.org/
>
> Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
>


-- 
Austin Ziegler • halostatue@gmail.com • austin@halostatue.ca
http://www.halostatue.ca/http://twitter.com/halostatue

[-- Attachment #1.2: Type: text/html, Size: 4182 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:91151] [Ruby trunk Bug#15544] sprintf returns an unexpected string
       [not found] <redmine.issue-15544.20190117195220@ruby-lang.org>
  2019-01-17 19:52 ` [ruby-core:91142] [Ruby trunk Bug#15544] sprintf returns an unexpected string andre.kullmann
@ 2019-01-17 22:28 ` shevegen
  2019-01-17 22:44 ` [ruby-core:91152] " shyouhei
  2 siblings, 0 replies; 4+ messages in thread
From: shevegen @ 2019-01-17 22:28 UTC (permalink / raw)
  To: ruby-core

Issue #15544 has been updated by shevegen (Robert A. Heiler).


You should use the bugtracker primarily for ruby-related problems, issues and so forth. For questions
about C not directly related to the ruby implementation, stackoverflow may be a better site.

----------------------------------------
Bug #15544: sprintf returns an unexpected string
https://bugs.ruby-lang.org/issues/15544#change-76382

* Author: areman01 (André Kullmann)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello,

I've a little problem with the sprintf function. It returns unexpected results ( in my opinion )

``` ruby
sprintf("%.16g", 8.78)
# returns "8.779999999999999"
# my expected result is "8.78"
```

Can somebody explain this behavior to me ?

Best Begards



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [ruby-core:91152] [Ruby trunk Bug#15544] sprintf returns an unexpected string
       [not found] <redmine.issue-15544.20190117195220@ruby-lang.org>
  2019-01-17 19:52 ` [ruby-core:91142] [Ruby trunk Bug#15544] sprintf returns an unexpected string andre.kullmann
  2019-01-17 22:28 ` [ruby-core:91151] " shevegen
@ 2019-01-17 22:44 ` shyouhei
  2 siblings, 0 replies; 4+ messages in thread
From: shyouhei @ 2019-01-17 22:44 UTC (permalink / raw)
  To: ruby-core

Issue #15544 has been updated by shyouhei (Shyouhei Urabe).

Status changed from Open to Rejected

Please visit https://bugs.ruby-lang.org/ and read the FAQ part.
Next time consider doing so before posting an issue.

----------------------------------------
Bug #15544: sprintf returns an unexpected string
https://bugs.ruby-lang.org/issues/15544#change-76383

* Author: areman01 (André Kullmann)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Hello,

I've a little problem with the sprintf function. It returns unexpected results ( in my opinion )

``` ruby
sprintf("%.16g", 8.78)
# returns "8.779999999999999"
# my expected result is "8.78"
```

Can somebody explain this behavior to me ?

Best Begards



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-17 22:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15544.20190117195220@ruby-lang.org>
2019-01-17 19:52 ` [ruby-core:91142] [Ruby trunk Bug#15544] sprintf returns an unexpected string andre.kullmann
2019-01-17 20:14   ` [ruby-core:91143] " Austin Ziegler
2019-01-17 22:28 ` [ruby-core:91151] " shevegen
2019-01-17 22:44 ` [ruby-core:91152] " shyouhei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).