🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

158 total messages Page 4 of 4 Started by fir Tue, 27 Oct 2026 10:53
Page 4 of 4 • 158 total messages
Re: .5 against 0.5f
#1271
Author: Lawrence D’Oliveiro
Date: Mon, 02 Nov 2026 20:20
10 lines
1595 bytes
On Mon, 2 Nov 2026 18:25:43 +0100, Bonita Montero wrote:

> If you have a proper fp to decimal runtime function this actually
> won't happen.

Or if you use a decimal rather than binary number representation in
the first place.

(Note this orthogonal to the issue of fixed-point versus
floating-point.)
Re: .5 against 0.5f
#1286
Author: Dan Cross
Date: Tue, 03 Nov 2026 08:45
34 lines
2111 bytes
In article <11c8dls$2chr0$1@dont-email.me>,
James Kuyper  <jameskuyper@alumni.caltech.edu> wrote:
>On 2026-10-29 17:55, Janis Papanagnou wrote:
>> On 2026-10-29 20:49, Dan Cross wrote:
>>> [...]
>>>
>>> But again, the whole premise (that a programmer familiar with C
>>> would ever think that `return` is a function) is silly.
>
>Agreed. The misconception is far more common among those
>who aren't very familiar with C.

It is not common at all.

>> Yes, that's hard to believe.
>
>See

No.  Cherry picking a few absurd examples from 20+ years of
USENET, probably some of which are easily explained by
non-native English speakers unxerstanding the construct but
simply using the wrong nomenclature, really does not prove
anything.  You could probably find examples of new programmers
being similarly confused by `while` and `if`, which I had
mentioned previously.

>It's not, by any means, a common misconception, but it does occur.

Not with any significant frequency or durability.  To the extent
that it ever happens, it is not the sort of error that survives
even casual experience.

	- Dan C.
Re: .5 against 0.5f
#1313
Author: Kaz Kylheku
Date: Tue, 03 Nov 2026 18:25
60 lines
3975 bytes
On 2026-11-03, Dan Cross <cross@spitfire.i.gajendra.net> wrote:
> In article <11c8dls$2chr0$1@dont-email.me>,
> James Kuyper  <jameskuyper@alumni.caltech.edu> wrote:
>>On 2026-10-29 17:55, Janis Papanagnou wrote:
>>> On 2026-10-29 20:49, Dan Cross wrote:
>>>> [...]
>>>>
>>>> But again, the whole premise (that a programmer familiar with C
>>>> would ever think that `return` is a function) is silly.
>>
>>Agreed. The misconception is far more common among those
>>who aren't very familiar with C.
>
> It is not common at all.

You have to get to a certain advanced level of education in computer
science before you start believing that returning is another function
calls.

But it's there. The returning control flow can be modeled by
continuations.

We can eliminate returns from a program by passing a context
argument to each function: the return continuation. The places
where the function returns become tail calls to the continuation.

The transformation of a program to continuation passing style ("CPS
transformation") can be done by a compiler, allowing a program in a
language in which ordinary function returning appears to work under the
hood by returns achieved by a function call.

How it works is that all the code that would take place in the
caller after a function returns is bundled into a lambda body,
and the lambda is passed as the continuation argument.

(This is now actually very familiar to youngsters who work in web front
end and know about "async" functions. In that paradigm, a kind of
continuation system appears whereby the computation we'd like to do from
now on, but only after some event is received, is farmed out to a
lambda.)

Famously, (to tie this back to C somehow), Chicken Scheme implements
continuation over the native stack in a particular way. Chicken Scheme
code is translated to C code, and that C code never returns from its
functions. It always passes a lambda to the callee.  Lambdas capture
their context on the stack. Because nothing ever returns, pointers and
other objects on the stack nicely persist: local variables don't die
after a function returns because it's compiled to a C function that
returns by calling a continuation. When the stack hits a certain limit,
it is rewound back to the top. At that time, all the objects in the
stack that are still live are identified and moved to the heap. I think,
even character strings in their entirety (the actual array) are
bump-allocated on the stack, and so have to be memmoved to the heap when
the stack rewinds, so the stack acts as a nursery for new objects.


-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Re: .5 against 0.5f
#1338
Author: Tim Rentsch
Date: Thu, 05 Nov 2026 14:31
28 lines
2556 bytes
antispam@fricas.org (Waldek Hebisch) writes:

> Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>
>> David Brown <david.brown@hesbynett.no> writes:
>>
>>> On 28/10/2026 21:25, Michael S wrote:
>>
>> [...]
>>
>>>> I'd still likely prefer to write it as (float)0.1 instead of 0.1f.
>>>> It somewhat depends on my mood in specific day, but likelihood is
>>>> certainly not in favor of 0.1f.
>>>
>>> That seems a bit excessive to me, but okay.  The principle is the
>>> same, making it clear to the reader and the compiler that no
>>> double-precision arithmetic is involved.
>>
>> Except that, at least in the abstract machine, `(float)0.1` produces
>> a value of type double and converts it to float.  It's likely that
>> a compiler would generate the same code as for `0.1f`, but I'd want
>> to confirm that if it mattered.  (Actually, I'd just write `0.1f`.)
>
> Maybe the code will be the same.  But in general going via doubles
> produces less accurate result, [...]

What makes you think using a double will produce a less accurate
result?
Re: .5 against 0.5f
#1343
Author: Waldek Hebisch
Date: Thu, 05 Nov 2026 22:07
50 lines
3366 bytes
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> antispam@fricas.org (Waldek Hebisch) writes:
> 
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>>
>>> David Brown <david.brown@hesbynett.no> writes:
>>>
>>>> On 28/10/2026 21:25, Michael S wrote:
>>>
>>> [...]
>>>
>>>>> I'd still likely prefer to write it as (float)0.1 instead of 0.1f.
>>>>> It somewhat depends on my mood in specific day, but likelihood is
>>>>> certainly not in favor of 0.1f.
>>>>
>>>> That seems a bit excessive to me, but okay.  The principle is the
>>>> same, making it clear to the reader and the compiler that no
>>>> double-precision arithmetic is involved.
>>>
>>> Except that, at least in the abstract machine, `(float)0.1` produces
>>> a value of type double and converts it to float.  It's likely that
>>> a compiler would generate the same code as for `0.1f`, but I'd want
>>> to confirm that if it mattered.  (Actually, I'd just write `0.1f`.)
>>
>> Maybe the code will be the same.  But in general going via doubles
>> produces less accurate result, [...]
> 
> What makes you think using a double will produce a less accurate
> result?

Going via doubles number in the C source will be rounded twice,
first time to a double, then the result of first runding will
be rounded second time.  Each rounding step introduces some
error.  Resonable heuristic says that errors may be close to
maximal possible and may add.  So error may be bigger than
from single rounding.

If you do not want to belive in the heuristic above, consider
IEEE arthmetic and two consequtive single precisin numbers
a and b.  Next, take double c in the middle of the interval
between a nad b.  According to IEEE "round to even" rule this
double will be rounded to one of the singles above, say a.  Take
source number d that rounds to c, but is on the side corresponding
to b.  Going via double will produce a as the result.  Directly
rounding to single will produce b.  It is clear that b is
closer to d than a, so double rounding in this case indeed
produces more error, that is less accuracy.

-- 
                              Waldek Hebisch
Re: .5 against 0.5f
#1350
Author: Dan Cross
Date: Fri, 06 Nov 2026 12:03
29 lines
1912 bytes
In article <20261103101134.247@kylheku.com>,
Kaz Kylheku  <046-301-5902@kylheku.com> wrote:
>On 2026-11-03, Dan Cross <cross@spitfire.i.gajendra.net> wrote:
>> In article <11c8dls$2chr0$1@dont-email.me>,
>> James Kuyper  <jameskuyper@alumni.caltech.edu> wrote:
>>>On 2026-10-29 17:55, Janis Papanagnou wrote:
>>>> On 2026-10-29 20:49, Dan Cross wrote:
>>>>> [...]
>>>>>
>>>>> But again, the whole premise (that a programmer familiar with C
>>>>> would ever think that `return` is a function) is silly.
>>>
>>>Agreed. The misconception is far more common among those
>>>who aren't very familiar with C.
>>
>> It is not common at all.
>
>You have to get to a certain advanced level of education in computer
>science before you start believing that returning is another function
>calls.
>
>But it's there. The returning control flow can be modeled by
>continuations.

Sure.  But you don't seriously believe that's what Kuyper was
referring to, do you?

	- Dan C.
Re: .5 against 0.5f
#1360
Author: Chris M. Thomasson
Date: Sat, 07 Nov 2026 03:23
36 lines
2920 bytes
On 10/29/2026 3:06 AM, David Brown wrote:
> On 28/10/2026 22:34, Chris M. Thomasson wrote:
>> On 10/28/2026 12:39 AM, David Brown wrote:
>>> On 28/10/2026 01:49, Lawrence D’Oliveiro wrote:
>>>> On Tue, 27 Oct 2026 18:06:25 -0400, James Kuyper wrote:
>>>>
>>>>> However, if you need double precision, you shouldn't be using the
>>>>> "f" suffix.
>>>>
>>>> Is there any situation where you *should* use the “f” suffix?
>>>>
>>>> I am thinking: no.
>>>
>>> Try thinking harder.
>>>
>>> I use the "f" suffix all the time in my code, because I do not want 
>>> double precision.  In many situations, single precision arithmetic is 
>>> at least twice as fast as double precision - in some situations it 
>>> can be two orders of magnitude faster.
>>>
>>>
>>
>> Same here. I am mostly creating graphics related things. double 
>> precision in a GPU might not be there. Now, if I am doing something 
>> that needs higher precision, tends to be with deep zooms or 
>> granularity in a vector field, then double is okay. But I need to 
>> beware that the shaders might not support double.
> 
> You can also see it in SIMD.  A 128-bit SIMD register might be useable 
> for 4 single-precision values and parallel operations, while only 2 can 
> be handled for double-precision.  Obviously details will vary by SIMD 
> implementation, but singles are going to be at least twice as fast in 
> general.
> 

Indeed....
Page 4 of 4 • 158 total messages
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads