From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 6036 invoked from network); 18 Aug 2021 04:12:56 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 18 Aug 2021 04:12:56 -0000 Received: from mail-io1-f44.google.com ([209.85.166.44]) by 1ess; Mon Aug 16 17:51:44 -0400 2021 Received: by mail-io1-f44.google.com with SMTP id a21so10035425ioq.6 for <9front@9front.org>; Mon, 16 Aug 2021 14:51:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:in-reply-to:references:organization :mime-version:content-transfer-encoding; bh=4ne7cC/SGR3Lc2NzQtEqfymDcUCi3ImBwcJKd2qLBFQ=; b=O5HnlRmLKk+eupLYDU2d0zF/HT/DPQ5hkSG1LZ3zxg/Ne3Lh8vIW0lwv9P1n02zVN+ A4QF4oD6p23529jjpCqaChDSFcGOGiFitCc9ai8bS5nArFzJo0gBIQdmNAWG7Eq8WBll 0XrCW/EhTmHv+cozw42Ljc79neZMgtYMZJQ6a+AGYN6O8854R80LP4yevuYgvjWx+LKh gGJawLo6ZbjBnB7TD30q1A5KxEzUi5qpBcSoyYcYowZXJaeOEvbWhN0yB6/unseh173G F5BltT1iNYeuK2+vCgL+I5LQqwPzGJAz6aKyFnt/DqS/q9DCX//kzf4dW+LmMjASUFqH Z6XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=4ne7cC/SGR3Lc2NzQtEqfymDcUCi3ImBwcJKd2qLBFQ=; b=o/G7Zw5akoATT9CaPccJvmYyxK72QLcWa9tnfBmT9FGQ82QkRjtH4AicMvdgh5jQef 71iKw6qRXQxKxzFiV0MfLWbr0fTWKNUB2tlWJ1k6HOHOWsOsFBoqnzAWJ4sru+51pOcd jgxNVd6uREQPqwN8yuQWHUZ7pLFPOCOdy//FVTOrLl9GOqLUjopumApm20a4KnTqEBpo GG/4zb5kFZbV8GMHtQE20zrpO1yxHrqUe34Ejqze+bIqkvuTs5drULksaSsiToPplmYG hwKR0aaHn5ALQTEUG9CA6EKBmRoHdJdfG5ADN5yvOMdNb6lpm3F8372/05JGt+RJUKI5 kydQ== X-Gm-Message-State: AOAM531MVHqPCmoQSLDCaxYGhoxYcgb+QTFcs1WV3IEJ/KG9tAmqnpvo VTsMeDu0XjeuzHh+W2nkLyf5soHlzKs= X-Google-Smtp-Source: ABdhPJxsN9MU2dHz0F+dOREwtCob7B1gXD6RU+6h5BhmXkWaDe/+8skSD0906yNsxKCk7WuULd9CNg== X-Received: by 2002:a05:6e02:1d11:: with SMTP id i17mr54255ila.33.1629150308231; Mon, 16 Aug 2021 14:45:08 -0700 (PDT) Return-Path: Received: from spruce.localdomain ([2601:246:4e03:dc20::575f]) by smtp.gmail.com with ESMTPSA id a4sm75570ioe.19.2021.08.16.14.45.08 for <9front@9front.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 14:45:08 -0700 (PDT) Date: Mon, 16 Aug 2021 16:45:04 -0500 From: Amavect To: 9front@9front.org Message-ID: <20210816164504.4341615e@spruce.localdomain> In-Reply-To: References: Organization: Amavect Industries X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: configuration ACPI package general-purpose locator Subject: Re: [9front] seq: fix infinite loop Reply-To: 9front@9front.org Precedence: bulk On Sun, 15 Aug 2021 15:02:38 -0700 Sean Hinchee wrote: > ; seq 2e16 20000000000000002 > would loop forever. At this range, 2e16 and 20000000000000002 are represented by the same double floating point value. > + if(val =3D=3D max) > + break; We can cover more cases. For example, your patch does not fix the following: seq 9007199254740992 9007199254740996 The issue is with floating point precision. A double has a 52 bit mantissa, meaning that it allows 2^52 different values before the exponent is incremented (thus, floating point.) A double has a 11 bit exponent, and 1 sign bit. Exponents range from =E2=88=921022 to +1023, with exponents =E2=88=921023 a= nd +1024 reserved for special numbers. At an exponent e, the mantissa represents a value between [2^e,2^(e+1)). The precision is range/buckets, so we can calculate the precision. At an exponent e and mantissa m, the precision is 2^(e-m) (2^(e+1)-2^e)/2^m =3D 2^e/2^m =3D 2^(e-m) Between [1, 2), the exponent is 0. The precision is 2^(0-52) =E2=89=88 0.0000000000000002220446 Between [2^52, 2^53), the exponent is 52. The precision is 2^(52-52) =3D 1. 2e16 is between [2^54, 2^55), so the exponent is 54. The precision is 2^(54-52) =3D 4. Halfway ties round to the even bucket. This is demonstrated by the following. # infinite loop seq 2e16 19999999999999998 # 2^53-1, halts seq 9007199254740991 9007199254740991 # 2^53, infinite loop due to halfway tie rounding down to even bucket. seq 9007199254740992 9007199254740992 # halts, halfway tie rounds up to even bucket, 9007199254740996 seq 9007199254740994 9007199254740994 # different due to rounding error in loss of precision seq 5000000000000000 1.1 5000000000000002 seq 0 1.1 2 I don't believe that there is an ideal resolution to rounding error in that last example (libmp would be too complex), but we can cover more cases if we check that the previous val value is different from the current val. The correct thing to do is to throw an error warning about precision. Thanks, Amavect