Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #402418 > unrolled thread
| Started by | fir <profesor.fir@gmail.com> |
|---|---|
| First post | 2026-09-27 10:20 +0200 |
| Last post | 2026-09-28 00:02 +0200 |
| Articles | 9 on this page of 129 — 16 participants |
Back to article view | Back to comp.lang.c
official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-27 10:20 +0200
Re: official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-27 20:04 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-27 21:38 +0100
Re: official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-27 23:16 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-28 00:53 +0100
Re: official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-28 04:31 +0200
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-28 10:25 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-28 11:45 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-28 13:56 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-28 14:38 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-28 16:12 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-28 16:52 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-28 18:49 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-28 20:26 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-29 09:45 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-29 12:54 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-29 15:56 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-29 18:15 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-29 20:24 +0200
Re: official library of tiny functions lacking in c scott@slp53.sl.home (Scott Lurndal) - 2026-09-29 19:41 +0000
Re: official library of tiny functions lacking in c cross@spitfire.i.gajendra.net (Dan Cross) - 2026-09-29 21:37 +0000
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-30 01:33 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-30 09:28 +0200
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-09-30 13:41 +0300
Re: official library of tiny functions lacking in c Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-10-01 07:25 -0700
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-10-01 17:50 +0300
Re: official library of tiny functions lacking in c Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-10-01 09:37 -0700
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-30 01:19 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-30 09:44 +0200
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-29 16:01 +0200
Re: official library of tiny functions lacking in c "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-09-30 01:00 -0700
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-30 13:01 +0200
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-10-01 08:52 +0000
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-30 01:56 +0000
Re: official library of tiny functions lacking in c Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-10-01 07:15 -0700
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-29 09:28 +0200
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-29 07:10 +0000
Re: official library of tiny functions lacking in c "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-09-28 15:30 -0700
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-29 09:03 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-29 11:11 +0100
Re: official library of tiny functions lacking in c scott@slp53.sl.home (Scott Lurndal) - 2026-09-29 14:38 +0000
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-30 07:02 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-30 11:35 +0100
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-30 14:14 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-30 13:45 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-30 15:30 +0200
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-09-30 17:14 +0300
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-30 16:42 +0200
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-09-30 18:02 +0300
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-30 16:54 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-30 18:26 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-30 22:12 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-10-01 09:44 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-10-01 10:42 +0100
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-10-01 13:50 +0300
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-10-01 12:29 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-10-02 09:35 +0200
Re: official library of tiny functions lacking in c Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-10-02 04:03 -0700
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-10-02 13:50 +0200
Re: official library of tiny functions lacking in c Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-10-02 11:22 -0700
Re: official library of tiny functions lacking in c gazelle@shell.xmission.com (Kenny McCormack) - 2026-10-02 18:33 +0000
Re: official library of tiny functions lacking in c scott@slp53.sl.home (Scott Lurndal) - 2026-10-03 14:30 +0000
Re: official library of tiny functions lacking in c Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-10-03 16:37 -0700
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-10-01 13:29 +0200
Re: official library of tiny functions lacking in c scott@slp53.sl.home (Scott Lurndal) - 2026-10-01 14:46 +0000
Re: official library of tiny functions lacking in c "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-10-01 15:37 -0700
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-10-02 08:57 +0200
Re: official library of tiny functions lacking in c "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-10-02 00:37 -0700
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-30 17:12 +0100
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-09-30 14:09 +0300
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-30 13:55 +0200
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-30 14:31 +0200
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-09-30 16:12 +0300
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-30 19:33 +0200
Re: official library of tiny functions lacking in c scott@slp53.sl.home (Scott Lurndal) - 2026-09-30 18:14 +0000
Re: official library of tiny functions lacking in c James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-10-01 08:34 -0400
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-29 07:08 +0000
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-29 15:02 +0100
Re: official library of tiny functions lacking in c scott@slp53.sl.home (Scott Lurndal) - 2026-09-29 14:43 +0000
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-29 16:07 +0100
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-29 22:58 +0000
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-30 00:13 +0100
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-30 07:13 +0000
Re: official library of tiny functions lacking in c Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-10-01 02:41 +0800
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-09-30 14:15 +0300
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-09-30 14:18 +0300
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-30 13:24 +0100
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-30 14:45 +0200
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-09-30 15:56 +0300
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-30 22:31 +0000
Re: official library of tiny functions lacking in c Michael S <already5chosen@yahoo.com> - 2026-09-30 14:32 +0300
Re: official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-28 17:22 +0200
Re: official library of tiny functions lacking in c Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-09-28 17:24 -0700
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-29 09:54 +0200
Re: official library of tiny functions lacking in c "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-09-29 16:48 -0700
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-28 14:16 +0200
Re: official library of tiny functions lacking in c James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-09-28 11:15 -0400
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-28 16:40 +0100
Re: official library of tiny functions lacking in c "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-09-29 16:50 -0700
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-29 06:38 +0000
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-29 14:36 +0100
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-29 22:49 +0000
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-29 23:59 +0100
Re: official library of tiny functions lacking in c "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-09-29 16:51 -0700
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-30 01:54 +0000
Re: official library of tiny functions lacking in c James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-09-29 22:09 -0400
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-30 10:52 +0100
Re: official library of tiny functions lacking in c David Brown <david.brown@hesbynett.no> - 2026-09-30 12:38 +0200
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-10-01 08:49 +0000
Re: official library of tiny functions lacking in c James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-10-01 08:48 -0400
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-28 06:45 +0000
Re: official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-28 12:42 +0200
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-29 00:58 +0000
Re: official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-29 03:02 +0200
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-29 03:16 +0000
Re: official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-29 14:20 +0200
Re: official library of tiny functions lacking in c Paul <nospam@needed.invalid> - 2026-09-29 12:39 -0400
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-29 22:50 +0000
Re: official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-30 02:57 +0200
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-30 02:00 +0000
Re: official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-30 10:08 +0200
Re: official library of tiny functions lacking in c fir <profesor.fir@gmail.com> - 2026-09-30 13:58 +0200
Re: official library of tiny functions lacking in c bart <bc@freeuk.com> - 2026-09-28 11:43 +0100
Re: official library of tiny functions lacking in c Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-29 01:00 +0000
Re: official library of tiny functions lacking in c Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-09-30 07:59 +0200
Re: official library of tiny functions lacking in c James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-09-28 11:03 -0400
Re: official library of tiny functions lacking in c NOTE fir <profesor.fir@gmail.com> - 2026-09-28 17:50 +0200
Re: official library of tiny functions lacking in c "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-09-30 12:42 -0700
Re: official library of tiny functions lacking in c tTh <tth@none.invalid> - 2026-09-28 00:02 +0200
Page 7 of 7 — ← Prev page 1 2 3 4 5 6 [7]
| From | fir <profesor.fir@gmail.com> |
|---|---|
| Date | 2026-09-30 10:08 +0200 |
| Message-ID | <119ig1c$1jv0$1@dont-email.me> |
| In reply to | #402532 |
Lawrence D’Oliveiro pisze: > On Wed, 30 Sep 2026 02:57:09 +0200, fir wrote: > >> Lawrence D’Oliveiro pisze: >>> >>> On Tue, 29 Sep 2026 14:20:23 +0200, fir wrote: >>> >>>> Lawrence D’Oliveiro pisze: >>>>> >>>>> Doesn’t correctness of the code figure into your thinking? >>>> >>>> what correctnes? >>> >>> We have here a standard library function, already implemented, that >>> provides better-quality results than your somewhat simplistic >>> attempt. Why should we bother with your code at all? >>> >> why you ask me all that nonsense quiestions? > > That’s a Donald-Trump-type answer -- attack the questioner as an > attempt to deflect from the issue at hand. > > Code is not something you write just because it feels good to type in > all those cryptic symbols. It’s got to do something useful, and > furthermore, do it correctly. > why you ask me idiotic questions and not answer mine?
[toc] | [prev] | [next] | [standalone]
| From | fir <profesor.fir@gmail.com> |
|---|---|
| Date | 2026-09-30 13:58 +0200 |
| Message-ID | <119iths$6n5t$1@dont-email.me> |
| In reply to | #402544 |
fir pisze: > Lawrence D’Oliveiro pisze: >> On Wed, 30 Sep 2026 02:57:09 +0200, fir wrote: >> >>> Lawrence D’Oliveiro pisze: >>>> >>>> On Tue, 29 Sep 2026 14:20:23 +0200, fir wrote: >>>> >>>>> Lawrence D’Oliveiro pisze: >>>>>> >>>>>> Doesn’t correctness of the code figure into your thinking? >>>>> >>>>> what correctnes? >>>> >>>> We have here a standard library function, already implemented, that >>>> provides better-quality results than your somewhat simplistic >>>> attempt. Why should we bother with your code at all? >>>> >>> why you ask me all that nonsense quiestions? >> >> That’s a Donald-Trump-type answer -- attack the questioner as an >> attempt to deflect from the issue at hand. >> >> Code is not something you write just because it feels good to type in >> all those cryptic symbols. It’s got to do something useful, and >> furthermore, do it correctly. >> > > > why you ask me idiotic questions and not answer mine? ok im 'trolling' you (i mean make fun wit your stupid behaviour) you come hera ask idiotic question - idiotic questions do not prove any stupid point and overally are slightly harmfull for this group too
[toc] | [prev] | [next] | [standalone]
| From | bart <bc@freeuk.com> |
|---|---|
| Date | 2026-09-28 11:43 +0100 |
| Message-ID | <119dgc1$28if0$1@dont-email.me> |
| In reply to | #402442 |
On 28/09/2026 07:45, Lawrence D’Oliveiro wrote:
> On Sun, 27 Sep 2026 20:04:20 +0200, fir wrote:
>
>> float len2(float x,float y) { return sqrtf(x*x+y*y);}
>
> Interesting:
>
> /*
> Comparison of the naïve calculation of a triangle
> hypotenuse with the standard-library hypot(3) function.
> */
>
> #include <math.h>
> #include <values.h>
> #include <stdio.h>
>
> static float len2(float x,float y) { return sqrtf(x*x+y*y);}
>
> static void compare_for
> (
> float x
> )
> {
> fprintf
> (
> stdout,
> "for %.7e: len2 = %.7e, hypot = %.7e\n",
> x, len2(x, x), hypotf(x, x)
> );
> } /*compare_for*/
This is a diabolic layout. I had to fix so that I can see what it was doing.
How can you stretch a one-line function to this length?!
> int main(void)
> {
> compare_for(FLT_MAX / 2.0f);
> compare_for(2.0 / FLT_MAX);
> return
> 0;
> } /*main*/
>
> Output:
>
> ldo@theon:c_try> !./
> ./naive_hypot
> for 1.7014117e+38: len2 = inf, hypot = 2.4061594e+38
> for 5.8774718e-39: len2 = 0.0000000e+00, hypot = 8.3120008e-39
> ldo@theon:c_try>
>
> How is it the standard library function is able to produce a
> reasonable-looking result where your function breaks down?
You mean a reasonable looking result for quite unreasonable inputs?
Because it's common to work with triangles whose sides are
170141173319264429905852091742258462720 units long!
The simple function squares its arguments, so the upper limit for first
test would be sqrt(FLT_MAX)/2.0 (since it also adds the two squares).
In that case both versions give the same result. For second test, where
you are working with triangles with non-zero sides smaller than
Plancks's Constant, I haven't dealt with.
Sure, the official version can deal with a wider range, but try it with
FLT_MAX and both fail.
In practice, for inputs this huge, it makes sense to switch to 'double'.
Then it will also work better for arbitrary expressions that happen to
use squares and other powers.
So I think this overhead for 'hypot' is pointless, given that, in
general, for any 'x' or type float, then x*x /anywhere in a program/
will overflow when x is bigger than sqrt(FLT_MAX).
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D’Oliveiro <ldo@nz.invalid> |
|---|---|
| Date | 2026-09-29 01:00 +0000 |
| Message-ID | <119f2iq$2rkb9$3@dont-email.me> |
| In reply to | #402447 |
On Mon, 28 Sep 2026 11:43:13 +0100, bart wrote: > You mean a reasonable looking result for quite unreasonable inputs? What’s “unreasonable” about it? It’s called “floating point” precisely because it is capable of covering such a wide dynamic range. And the answers in those cases are also within the representable dynamic range. And there are ways of computing those answers, which the naïve calculation completely fails to do.
[toc] | [prev] | [next] | [standalone]
| From | Janis Papanagnou <janis_papanagnou+ng@hotmail.com> |
|---|---|
| Date | 2026-09-30 07:59 +0200 |
| Message-ID | <119i8gc$3qujh$1@dont-email.me> |
| In reply to | #402447 |
On 2026-09-28 12:43, bart wrote: > On 28/09/2026 07:45, Lawrence D’Oliveiro wrote: >> [...] > > You mean a reasonable looking result for quite unreasonable inputs? > > Because it's common to work with triangles whose sides are > 170141173319264429905852091742258462720 units long! > > The simple function squares its arguments, so the upper limit for first > test would be sqrt(FLT_MAX)/2.0 (since it also adds the two squares). > > In that case both versions give the same result. For second test, where > you are working with triangles with non-zero sides smaller than > Plancks's Constant, I haven't dealt with. > > Sure, the official version can deal with a wider range, but try it with > FLT_MAX and both fail. > > In practice, for inputs this huge, it makes sense to switch to 'double'. > > Then it will also work better for arbitrary expressions that happen to > use squares and other powers. > > So I think this overhead for 'hypot' is pointless, given that, in > general, for any 'x' or type float, then x*x /anywhere in a program/ > will overflow when x is bigger than sqrt(FLT_MAX). Numeric math is not something I'm doing or that I did professionally. So just a few general comments. While I think it's nowadays less an issue than in the days of smaller 'float's there's still high demands from numerical math applications. Small differences can change the overall results of a complex numeric algorithm significantly; we know that from chaotic systems (weather forecasts) or complex hydrodynamic systems (as I've heard from that area). In numerical math you need stable functions with good error propagation characteristics. And, frankly, I'm not sure I'm nowadays as concerned about the MAX being insufficient, rather about whether the MIN, the resolution might suffice. Anyway, as I'm no expert in that area - and I suppose most programmers are no experts - I'm glad that there's competent people who are writing such library functions for us that provide the best characteristics for those purposes! If you, personally, don't need such stable functions and algorithms that's fine. If you don't know where to obtain/find such algorithms, whether hypot() or the huge set of functions you find in professional math libraries, it may not matter [to you]. (I'm fine with that.) But regularly I wonder about your constant complaints, whining, and statements about something you don't see or need as being unnecessary. Janis
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2026-09-28 11:03 -0400 |
| Message-ID | <119dvjn$2ek5a$1@dont-email.me> |
| In reply to | #402442 |
On 2026-09-28 02:45, Lawrence D’Oliveiro wrote:
> On Sun, 27 Sep 2026 20:04:20 +0200, fir wrote:
>
>> float len2(float x,float y) { return sqrtf(x*x+y*y);}
>
> Interesting:
>
> /*
> Comparison of the naïve calculation of a triangle
> hypotenuse with the standard-library hypot(3) function.
> */
>
> #include <math.h>
> #include <values.h>
> #include <stdio.h>
>
> static float len2(float x,float y) { return sqrtf(x*x+y*y);}
>
> static void compare_for
> (
> float x
> )
> {
> fprintf
> (
> stdout,
> "for %.7e: len2 = %.7e, hypot = %.7e\n",
> x, len2(x, x), hypotf(x, x)
> );
> } /*compare_for*/
>
> int main(void)
> {
> compare_for(FLT_MAX / 2.0f);
> compare_for(2.0 / FLT_MAX);
> return
> 0;
> } /*main*/
>
> Output:
>
> ldo@theon:c_try> !./
> ./naive_hypot
> for 1.7014117e+38: len2 = inf, hypot = 2.4061594e+38
> for 5.8774718e-39: len2 = 0.0000000e+00, hypot = 8.3120008e-39
> ldo@theon:c_try>
>
> How is it the standard library function is able to produce a
> reasonable-looking result where your function breaks down?
See
<https://en.wikipedia.org/wiki/Pythagorean_addition#Calculation_order>
for details about how that can be achieved.
[toc] | [prev] | [next] | [standalone]
| From | fir <profesor.fir@gmail.com> |
|---|---|
| Date | 2026-09-28 17:50 +0200 |
| Subject | Re: official library of tiny functions lacking in c NOTE |
| Message-ID | <119e2bd$2foug$1@dont-email.me> |
| In reply to | #402430 |
fir pisze:
> fir pisze:
>> you know there are a lacking tiny functions in c-lib
>> (by c-lib i mean those standard c includes all know)
>>
>> AND if people use many maybe there is a need to standarize it
>> byslef? if you need some could be ggood candidates for standarisation
>> maybe write it here (i mean whole body of such function)
>>
>> we could and should discuss them
>
>
> maybe something liek this?
>
>
> int mini(int a,int b) { return a<b?a:b; }
> int maxi(int a,int b) { return a>b?a:b; }
> float minf(float a,float b) { return a<b?a:b; }
> float maxf(float a,float b) { return a>b?a:b; }
> int absi(int x) { return x<0?-x:x; }
> float absf(float x) { return x<0?-x:x; }
> float signf(float x) { return x>0?1:x<0?-1:0; }
> int signi(int x) { return x>0?1:x<0?-1:0; }
>
> //above controversial?
>
> int clampi(int x,int a,int b) { return x<a?a:x>b?b:x; }
> float clampf(float x,float a,float b) { return x<a?a:x>b?b:x; }
> int betweeni(int x,int a,int b) { return x>=a && x<=b; }
>
> float lerp(float a,float b,float t) { return a+(b-a)*t; }
> float inv_lerp(float a,float b,float x) { return (x-a)/(b-a); }
> float remap(float x,float a,float b,float c,float d) { return
> c+(x-a)*(d-c)/(b-a); }
> float rad(float x) { return x*PI/180.0f; }
> float deg(float x) { return x*180.0f/PI; }
>
> //thise above i dont quite use
>
> float dist2_square(float x1,float y1,float x2,float y2) { float
> x=x2-x1,y=y2-y1; return x*x+y*y; }
> float dist2(float x1,float y1,float x2,float y2) { return
> sqrtf(dist2(x1,y1,x2,y2));}
> float len2_square(float x,float y) { return x*x+y*y; }
> float len2(float x,float y) { return sqrtf(x*x+y*y);}
> float dot2(float ax,float ay,float bx,float by){ return ax*bx+ay*by;}
> float cross2(float ax,float ay,float bx,float by){ return ax*by-ay*bx;}
> void norm2(float *x,float *y) { float d=sqrtf(*x**x+*y**y); if(d>0)
> { *x/=d; *y/=d; }}
> float dist2_to_line(float px,float py,float ax,float ay,float bx,float
> by){ return fabsf(cross2(bx-ax,by-ay,px-ax,py-ay))
> /sqrtf(dist2_square(ax,ay,bx,by));}
>
> // hare names may be controversial
>
> the fact is imo though people should generallu decide and use one set of
> such names imo
>
> there is also more functions to put here
NOTE what i say/ask here also has a quite practical dimension as i
revrite somewhat my old green file library and i may revrite the
basic functions and need to chose them.. mostly its about the names
though not only
for example i not sure for rand functions i consider some like that
int randi(int n) {return rand() % (n + 1);}
int randi2(int a, int b) { return a + rand() % (b - a + 1);}
float randf(float a) { return a*(float)rand() / (float)RAND_MAX; }
float randf2(float a, float b) { return a + randf( b - a);}
/* rand: return pseudo-random integer on 0..32767 */
enum {FRAND_MAX = 32767};
unsigned long int frand_next = 1;
int frand(void) { frand_next = frand_next * 1103515245 + 12345;
return (unsigned int)(frand_next/65536) % 32768; }
void frand_seed(unsigned int seed) { frand_next = seed; }
int frandi(int n) {return frand() % (n + 1);}
int frandi2(int a, int b) { return a + frand() % (b - a + 1);}
float frandf(float a) { return a*(float)frand() / (float)FRAND_MAX; }
float frandf2(float a, float b) { return a + frandf(b-a);}
those fast rand i not much tested unly roughly and the advantage is
this frand() seem to be almost 10x faster than std c rand()
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2026-09-30 12:42 -0700 |
| Message-ID | <119jono$hq9k$1@dont-email.me> |
| In reply to | #402430 |
On 9/27/2026 11:04 AM, fir wrote:
> fir pisze:
>> you know there are a lacking tiny functions in c-lib
>> (by c-lib i mean those standard c includes all know)
>>
>> AND if people use many maybe there is a need to standarize it
>> byslef? if you need some could be ggood candidates for standarisation
>> maybe write it here (i mean whole body of such function)
>>
>> we could and should discuss them
>
>
> maybe something liek this?
>
>
> int mini(int a,int b) { return a<b?a:b; }
> int maxi(int a,int b) { return a>b?a:b; }
> float minf(float a,float b) { return a<b?a:b; }
> float maxf(float a,float b) { return a>b?a:b; }
> int absi(int x) { return x<0?-x:x; }
> float absf(float x) { return x<0?-x:x; }
> float signf(float x) { return x>0?1:x<0?-1:0; }
> int signi(int x) { return x>0?1:x<0?-1:0; }
>
> //above controversial?
>
> int clampi(int x,int a,int b) { return x<a?a:x>b?b:x; }
> float clampf(float x,float a,float b) { return x<a?a:x>b?b:x; }
> int betweeni(int x,int a,int b) { return x>=a && x<=b; }
>
> float lerp(float a,float b,float t) { return a+(b-a)*t; }
> float inv_lerp(float a,float b,float x) { return (x-a)/(b-a); }
> float remap(float x,float a,float b,float c,float d) { return c+(x-
> a)*(d-c)/(b-a); }
> float rad(float x) { return x*PI/180.0f; }
> float deg(float x) { return x*180.0f/PI; }
>
> //thise above i dont quite use
>
> float dist2_square(float x1,float y1,float x2,float y2) { float x=x2-
> x1,y=y2-y1; return x*x+y*y; }
> float dist2(float x1,float y1,float x2,float y2) { return
> sqrtf(dist2(x1,y1,x2,y2));}
> float len2_square(float x,float y) { return x*x+y*y; }
> float len2(float x,float y) { return sqrtf(x*x+y*y);}
> float dot2(float ax,float ay,float bx,float by){ return ax*bx+ay*by;}
> float cross2(float ax,float ay,float bx,float by){ return ax*by-ay*bx;}
> void norm2(float *x,float *y) { float d=sqrtf(*x**x+*y**y); if(d>0)
> { *x/=d; *y/=d; }}
> float dist2_to_line(float px,float py,float ax,float ay,float bx,float
> by){ return fabsf(cross2(bx-ax,by-ay,px-ax,py-ay)) /
> sqrtf(dist2_square(ax,ay,bx,by));}
>
> // hare names may be controversial
>
> the fact is imo though people should generallu decide and use one set of
> such names imo
>
> there is also more functions to put here
Go for say GLSL. Oh wait, that's already a std. HLSL? Another std. For c++:
https://github.com/g-truc/glm
Oh wait, it does not need to be std in the language.
[toc] | [prev] | [next] | [standalone]
| From | tTh <tth@none.invalid> |
|---|---|
| Date | 2026-09-28 00:02 +0200 |
| Message-ID | <119c3pu$16bm$1@news.gegeweb.eu> |
| In reply to | #402418 |
On 9/27/26 10:20, fir wrote:
> AND if people use many maybe there is a need to standarize it
> byslef? if you need some could be ggood candidates for standarisation
> maybe write it here (i mean whole body of such function)
>
> we could and should discuss them
double dtime(void)
{
struct timeval t;
double d;
(void)gettimeofday(&t, NULL);
d = (double)t.tv_sec + (double)t.tv_usec / 1e6;
return d;
}
--
** **
* tTh des Bourtoulots *
* http://maison.tth.netlib.re/ *
** **
[toc] | [prev] | [standalone]
Page 7 of 7 — ← Prev page 1 2 3 4 5 6 [7]
Back to top | Article view | comp.lang.c
csiph-web