From dev-return-51976-archive-asf-public=cust-asf.ponee.io@thrift.apache.org Sun Mar 18 11:59:05 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 40C91180645 for ; Sun, 18 Mar 2018 11:59:05 +0100 (CET) Received: (qmail 36737 invoked by uid 500); 18 Mar 2018 10:59:04 -0000 Mailing-List: contact dev-help@thrift.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@thrift.apache.org Delivered-To: mailing list dev@thrift.apache.org Received: (qmail 36726 invoked by uid 99); 18 Mar 2018 10:59:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Mar 2018 10:59:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id C73A7C05CF for ; Sun, 18 Mar 2018 10:59:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -110.311 X-Spam-Level: X-Spam-Status: No, score=-110.311 tagged_above=-999 required=6.31 tests=[ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_DEF_SPF_WL=-7.5, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id pmIiOVHqh0cW for ; Sun, 18 Mar 2018 10:59:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id CFCF85F19C for ; Sun, 18 Mar 2018 10:59:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id AA7B6E023A for ; Sun, 18 Mar 2018 10:59:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 231752127D for ; Sun, 18 Mar 2018 10:59:00 +0000 (UTC) Date: Sun, 18 Mar 2018 10:59:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@thrift.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (THRIFT-4476) Typecasting problem on list items MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/THRIFT-4476?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D164= 03957#comment-16403957 ]=20 ASF GitHub Bot commented on THRIFT-4476: ---------------------------------------- Github user ozymaxx commented on a diff in the pull request: https://github.com/apache/thrift/pull/1496#discussion_r175284886 =20 --- Diff: compiler/cpp/src/thrift/generate/t_generator.h --- @@ -268,6 +271,30 @@ class t_generator { return out.str(); } =20 + const std::string emit_double_as_string(const double value) { + std::stringstream double_output_stream; + // sets the maximum precision: http://en.cppreference.com/w/cpp/= io/manip/setprecision + // sets the output format to fixed: http://en.cppreference.com/w= /cpp/io/manip/fixed (not in scientific notation) + double_output_stream << std::setprecision(std::numeric_limits::digits10 + 1); + + #ifdef _MSC_VER + // strtod is broken in MSVC compilers older than 2015, so st= d::fixed fails to format a double literal. + // more details: https://blogs.msdn.microsoft.com/vcblog/201= 4/06/18/ + // c-runtime-crt-features-fixes-and-breaking-c= hanges-in-visual-studio-14-ctp1/ + // and + // http://www.exploringbinary.com/visual-c-plu= s-plus-strtod-still-broken/ + #if _MSC_VER >=3D MSC_2015_VER + double_output_stream << std::fixed; + #endif + #else + double_output_stream << std::fixed; --- End diff -- =20 No, in both cases it should use `std::fixed`, that outputs the fixed fl= oating point representation of the number. But if the MSVC compiler is olde= r than 2015, that function is broken, and should not be called. In short, w= e want the compiler to generate the doubles in the fixed floating point rep= resentation if possible. On the Erlang side, if the compiler is older than = 2015, we want the compiler to use `std::scientific` since there can be case= s where the mantissa is being output as integer, which is illegal. `std::sc= ientific` always outputs the floating points numbers with a floating point = mantissa. But if it is 2015 or later, `std::fixed` works correctly and can = be used to get rid of the exponent representation.=20 > Typecasting problem on list items > --------------------------------- > > Key: THRIFT-4476 > URL: https://issues.apache.org/jira/browse/THRIFT-4476 > Project: Thrift > Issue Type: Bug > Components: Java - Compiler > Affects Versions: 0.11.0 > Reporter: Ozan Can Altiok > Priority: Major > > I was trying to add the following into=C2=A0a thrift interface file. > {{const list timeCoefficients =3D=C2=A0[24, 60, 60, 1000, 1000, 1= 000]}} > With the definition given above the {{.thrift}} file compiled properly. H= owever, I noticed that in Python, the items in=C2=A0{{timeCoefficients}}=C2= =A0are considered to be integer although the list has been defined to inclu= de items of {{double}} type. Then I modified the definition as given below = to make sure all the items are of type {{double}}.=C2=A0 > {{const list timeCoefficients =3D=C2=A0[24.0, 60.0, 60.0, 1000.0,= 1000.0, 1000.0]}} > After the change, I ran into the following error during compilation. > {{[ERROR]=C2=A0.../TimeCoefficients.java:[402,48]=C2=A0error: no suitable= method found for add(int)}} > {{[ERROR]=C2=A0method Collection.add(Double) is not applicable}} > {{[ERROR]=C2=A0(argument mismatch; int cannot be converted to Double)}} > {{[ERROR]=C2=A0method List.add(Double) is not applicable}} > {{[ERROR]=C2=A0(argument mismatch; int cannot be converted to Double)}} > Next, I changed the line as follows and the compilation became successful= . > {{const list timeCoefficients =3D=C2=A0[24.1, 60.1, 60.1, 1000.1,= 1000.1, 1000.1]}} > When I reviewed the generated Java source files, I=C2=A0discovered that > {{const list timeCoefficients =3D=C2=A0[24, 60, 60, 1000, 1000, 1= 000]}} > compiles to > {{public static final java.util.List timeCoefficients = =3D new java.util.ArrayList();}} > {{static {}} > {{=C2=A0 timeCoefficients.add((double)24);}} > {{=C2=A0 timeCoefficients.add((double)60);}} > {{=C2=A0 timeCoefficients.add((double)60);}} > {{=C2=A0 timeCoefficients.add((double)1000);}} > {{=C2=A0 timeCoefficients.add((double)1000);}} > {{=C2=A0 timeCoefficients.add((double)1000);}} > {{}}} > whilst > {{const list timeCoefficients =3D=C2=A0[24.0, 60.0, 60.0, 1000.0,= 1000.0, 1000.0]}} > compiles to > {{public static final java.util.List timeCoefficients = =3D new java.util.ArrayList();}} > {{static {}} > {{=C2=A0 timeCoefficients.add(24);}} > {{=C2=A0 timeCoefficients.add(60);}} > {{=C2=A0 timeCoefficients.add(60);}} > {{=C2=A0 timeCoefficients.add(1000);}} > {{=C2=A0 timeCoefficients.add(1000);}} > {{=C2=A0 timeCoefficients.add(1000);}} > {{}}} > which leads to an error. > When I modified this line as follows > {{const list timeCoefficients =3D=C2=A0[24.1, 60.1, 60.1, 1000.1,= 1000.1, 1000.1]}} > this line compiled to > {{public static final java.util.List timeCoefficients = =3D new java.util.ArrayList();}} > {{static {}} > {{=C2=A0 timeCoefficients.add(24.1);}} > {{=C2=A0 timeCoefficients.add(60.1);}} > {{=C2=A0 timeCoefficients.add(60.1);}} > {{=C2=A0 timeCoefficients.add(1000.1);}} > {{=C2=A0 timeCoefficients.add(1000.1);}} > {{=C2=A0 timeCoefficients.add(1000.1);}} > {{}}} > My guess is that, even if I put=C2=A0{{.0}}=C2=A0at the end of each numer= ic constant, on the Java side, Thrift compiler considers them to be=C2=A0{{= double}} and does no typecasts. However, the {{.0}} s are getting lost some= where and the items become integers in the generated Java code. Thus, when = it comes to populating the array, Java cannot succeed.=C2=A0{{Double}}=C2= =A0s cannot be unboxed to integer and Java thinks=C2=A0{{int}}=C2=A0and=C2= =A0{{Double}}=C2=A0are not related. -- This message was sent by Atlassian JIRA (v7.6.3#76005)