From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id ADLMKahVeGSVUAAASxT56A (envelope-from ) for ; Thu, 01 Jun 2023 10:24:08 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id GK/1KahVeGSIxAAA9RJhRA (envelope-from ) for ; Thu, 01 Jun 2023 10:24:08 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6AA692714A for ; Thu, 1 Jun 2023 10:24:08 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4daU-000469-UJ; Thu, 01 Jun 2023 04:23:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4daT-00045z-NO for emacs-orgmode@gnu.org; Thu, 01 Jun 2023 04:23:13 -0400 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4daP-0000vp-OY for emacs-orgmode@gnu.org; Thu, 01 Jun 2023 04:23:13 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id C77CF24002D for ; Thu, 1 Jun 2023 10:23:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1685607784; bh=QNNf/U6hwVKJGCAKd45K933HE6/9F16DN58q+tzoHBY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=dPwo4zU5Mqk2KzjocDUc0b4m/2Znvx8CQDlmgqOf7XD+KNFnwtc+JeaqGX8UsKarD Iw5AeT06yAwHh5EfSuLNR3ZqqbJMBecjFZ//XfhxDqCqVsqaq7AzSpMeP5yyp0c3yn Gd8jDChulV1zoZc6NpIPTaNsC7LIlmYtJZFaJfDzUkrI0SE2m7Y8IIdMD7qcqbu4oj /jgdoCBEZflvyuzOagYh7/lBr3Jivhn26O3bYdVSQ9SKfXTBmk4Z3GIfA/J2qQIfT1 Mzoswd7snsjNV5PFIxzUAudk5eJ0Ekjc01jPsoNls8v6TYZcxBvygVXRrvGycASBTs RYs2QFC9z8EqA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QWzfJ09f9z9rxH; Thu, 1 Jun 2023 10:23:03 +0200 (CEST) From: Ihor Radchenko To: Leo Butler Cc: Org Mode Mailing List Subject: Re: [PATCH] float format specifier in ob-C.el In-Reply-To: <87pm6g4ina.fsf@t14.reltub.ca> References: <87pm6g4ina.fsf@t14.reltub.ca> Date: Thu, 01 Jun 2023 08:27:33 +0000 Message-ID: <87leh3bn9m.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1685607848; a=rsa-sha256; cv=none; b=auJvhUlF3Ba2rZ2GhmViMVhxtaCce9N/FPOVg7DGbh6UhKKpJRyP2TPPLApKwViOKQiuWH m3c8gv2JnBqn99ULCwtzyr+g+ebq7n/qznEJc8ZPBqb9nJGuzqO306w/dq/7vHHLCl2yUC hjl+y8/mmx4ABW/BmVEwXyxLF6qjybpNezAU64kYBl2gZW5hglvYMo9YogwRWjnhtJTCi7 o46OgDcBTUkT//xUAqu/irSWAnXfbbo19CO6HMcT2nn3WPo32ivjDs8x3ni+E2VC0ghxQD CuGR28PJQqK5GBa0MnfQDXebfgPFPer4yc7q9UAkC3WVEnUHI3jy0FjjLYIR5Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=dPwo4zU5; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1685607848; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=ya/Mir4Ws1yUN9JKDs4q3tKQEfVp1JX8BWEFiPjGQ3s=; b=RaUkEMQNqdmoIbTbRS5bXnp+f4YjcoZLd5DuIKYGYCT6PiOCAc/BWvjMpJcTnbqdWNosXF HKpxArSmSP0ua4jjxZgKiCZ+ox44OSYJL/5jmPWZhEKC1I6DDN9lFAQLPeqO61tNQDvWOv CoeNyj1PdaPdu7kIfh2O8eOm5STLJErNmY9cjxFmTL7P+totOzVW8lNkOH/v+qe9/zWL2O 0e/jKhICRYg7gCw1JuWKmqeePB6GJAYVfEPltdDJkcQk18d7p5OY0VshB0uFci/R/A24zH 41dLSwLX3gX1wjXpOJZOyNWplUgriT46cGqKIBKSL6aXOyW7mG/bVEH/+hmNFA== Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=dPwo4zU5; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -11.12 X-Spam-Score: -11.12 X-Migadu-Queue-Id: 6AA692714A X-TUID: 1ietwvPk8DS0 Leo Butler writes: > In ob-C.el, line 339 has the format specifier > > (`floatp '("double" "%f")) > > to print literal floats. However, that format specifier rounds, which > can result in errors. I think the correct approach is to print the > float without rounding or padding or trying to guess at the desired > accuracy (and let the compiler do whatever is needed): > > (`floatp '("double" "%s")) Makes sense. Thanks! > - (`floatp '("double" "%f")) > + (`floatp '("double" "%s")) Please add comment explaining why not %f. Otherwise, it is not fully clear why "%s" is used. > --- a/testing/examples/ob-C-test.org > +++ b/testing/examples/ob-C-test.org > @@ -60,6 +60,12 @@ > return 0; > #+end_src > > +#+source: float_var > +#+begin_src cpp :var x=1.123456789012345678 :includes "" :results silent > +double y = 1.123456789012345678; > +std::cout << (x == y); > +#+end_src Please move the source block directly into the test using `org-test-with-temp-text'. The test will be more readable then. `org-test-at-id' should better be used only when necessary in order to not jump back and forth when debugging tests. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at