- **C Programming**
(*http://www.velocityreviews.com/forums/f42-c-programming.html*)

- - **sqrtl(), etc. for Cygwin**
(*http://www.velocityreviews.com/forums/t954298-sqrtl-etc-for-cygwin.html*)

sqrtl(), etc. for CygwinI've been using Cygwin lately, and am largely satisfied.
It has gcc, but lacks sqrtl(), atan2l(), etc. What's the recommended remedy? I Googled "source sqrtl" and got to codeforge.com but only AFTER passing one painful Gotcha test was I told I'd need another password. I'd bother with making a free(?) account if I were sure codeforge.com is the best piece of cheese in the maze, but it was just a random Google hit and it seemed wiser to ask the experts here. (I downloaded Cygwin just a few months ago -- why doesn't its gcc have sqrtl?) James |

Re: sqrtl(), etc. for CygwinOn 11/7/2012 1:40 PM, James Dow Allen wrote:
> I've been using Cygwin lately, and am largely satisfied. > It has gcc, but lacks sqrtl(), atan2l(), etc. > > What's the recommended remedy? > I Googled "source sqrtl" and got to codeforge.com > but only AFTER passing one painful Gotcha test > was I told I'd need another password. > > I'd bother with making a free(?) account if I were sure > codeforge.com is the best piece of cheese in the maze, > but it was just a random Google hit and > it seemed wiser to ask the experts here. > (I downloaded Cygwin just a few months ago -- > why doesn't its gcc have sqrtl?) A web search for "Cygwin long double" suggests that this lack is a long-standing issue, possibly with roots in licensing land. Maybe if you grovel through the search results more thoroughly than I did, you'll find something more helpful ... -- Eric Sosman esosman@comcast-dot-net.invalid |

Re: sqrtl(), etc. for CygwinJames Dow Allen <jdallen2000@yahoo.com> writes:
> I've been using Cygwin lately, and am largely satisfied. > It has gcc, but lacks sqrtl(), atan2l(), etc. > > What's the recommended remedy? > I Googled "source sqrtl" and got to codeforge.com > but only AFTER passing one painful Gotcha test > was I told I'd need another password. > > I'd bother with making a free(?) account if I were sure > codeforge.com is the best piece of cheese in the maze, > but it was just a random Google hit and > it seemed wiser to ask the experts here. > (I downloaded Cygwin just a few months ago -- > why doesn't its gcc have sqrtl?) gcc doesn't have sqrtl() on any system. It's part of the runtime library, not the compiler. That's not just a quibble; most or all Linux-based systems use the GNU C library, but Cygwin apparently uses something else. I don't know *why* Cygwin's runtime library doesn't provide sqrtl(), but here's part of the Cygwin man page for sqrt(): PORTABILITY `sqrt' is ANSI C. `sqrtf' is an extension. Both sqrtf and sqrtl were added to the ISO C standard in 1999, so the man page is badly out of date (though apparently no more so than the runtime library itself). I know there are problems with the representation of long double; gcc uses one size, and Microsoft uses another. This causes problems with the MinGW port of gcc. The Cygwin problem could be related to that. Of course you can always use sqrt() instead of sqrtl(), at the cost of some loss of precision (but if you didn't care about that you probably wouldn't be using long double in the first place). -- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> Will write code for food. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |

Re: sqrtl(), etc. for CygwinOn Wed, 07 Nov 2012 12:15:58 -0800, Keith Thompson wrote:
> James Dow Allen <jdallen2000@yahoo.com> writes: >> I've been using Cygwin lately, and am largely satisfied. >> It has gcc, but lacks sqrtl(), atan2l(), etc. >> >> What's the recommended remedy? >> I Googled "source sqrtl" and got to codeforge.com >> but only AFTER passing one painful Gotcha test >> was I told I'd need another password. >> >> I'd bother with making a free(?) account if I were sure >> codeforge.com is the best piece of cheese in the maze, >> but it was just a random Google hit and >> it seemed wiser to ask the experts here. >> (I downloaded Cygwin just a few months ago -- >> why doesn't its gcc have sqrtl?) > > > Of course you can always use sqrt() instead of sqrtl(), at the cost of > some loss of precision (but if you didn't care about that you probably > wouldn't be using long double in the first place). As long as one is disinteresting in x = inf, NaN, and possibly -0. You can do #include <math.h> long double foo_sqrtl(long double x) { long double r; r = sqrt((double)x); return ((r + (x / r))/2); } The tricky part is making the above compliant with IEEE 754. -- steve |

Re: sqrtl(), etc. for CygwinSteven G. Kargl <sgk@removetroutmask.apl.washington.edu> wrote:
(snip) > As long as one is disinteresting in x = inf, NaN, and possibly -0. You > can do > #include <math.h> > long double > foo_sqrtl(long double x) > { > long double r; > r = sqrt((double)x); > return ((r + (x / r))/2); > } I might have done two rounds to be sure. Also, the last one should be return(x/r+(r-x/r)/2); if you might be on a non-base2 system, such as IBM hex floating point or decimal floating point. > The tricky part is making the above compliant with IEEE 754. -- glen |

Re: sqrtl(), etc. for CygwinOn Nov 7, 1:40*pm, James Dow Allen <jdallen2...@yahoo.com> wrote:
> I've been using Cygwin lately, and am largely satisfied. > It has gcc, but lacks sqrtl(), atan2l(), etc. > > What's the recommended remedy? > I Googled "source sqrtl" and got to codeforge.com > but only AFTER passing one painful Gotcha test > was I told I'd need another password. > > I'd bother with making a free(?) account if I were sure > codeforge.com is the best piece of cheese in the maze, > but it was just a random Google hit and > it seemed wiser to ask the experts here. > (I downloaded Cygwin just a few months ago -- > why doesn't its gcc have sqrtl?) \code #include <stdio.h> #define c_sizeof_array(arr) (sizeof (arr) / sizeof ((arr)[0])) const double tolerance = 0.0000001; const int max_iterations = 10; double heron_sqrt( double x ); int main( void ) { size_t idx; char tmp_str[40]; double input[] = { 0, 1, 10, 100, 1000, 10000, 0.1, 0.25, -1 }; for ( idx = 0; idx < c_sizeof_array (input); ++idx ) { snprintf( tmp_str, sizeof (tmp_str), "sqrt( %.2f )", input[idx] ); printf( "%-20s = %.10f\n", tmp_str, heron_sqrt( input[idx] ) ); } return 0; } double heron_sqrt( double x ) { /* * The algorithm used to calculate the square root 'x' of number 'S' * is based on Heron's method. * * Let x(0) be an arbitrary positive number. * Let x(n+1) be the average of x(n) and 'S / x(n)' * Repeat until the desired accuracy is achieved. * * The closer x(0) is to the square root value, the fewer number * of iterations are needed to converge to the accuracy required. * * The global variable 'max_iterations' allows the person to * limit the accuracy of the result. */ double sqrt_x = 0; double guess = 0; double error = 0; int itr = 0; if ( x == 0.0 ) { sqrt_x = 0; } else { sqrt_x = x * 0.5; do { guess = sqrt_x; sqrt_x = 0.5 * ( guess + x / guess ); error = sqrt_x * sqrt_x - x; error = error < 0 ? -error : error; ++itr; } while ( error > tolerance && itr < max_iterations ); } return sqrt_x; } \endcode There are some issues, like how you want to deal with negative numbers, but you should be able to patch the algorithm up to create a workable substitute for 'sqrtl' by replacing the type with 'long double'. Best regards, John D. |

Re: sqrtl(), etc. for CygwinOn Wed, 07 Nov 2012 20:52:33 +0000, glen herrmannsfeldt wrote:
> Steven G. Kargl <sgk@removetroutmask.apl.washington.edu> wrote: > > (snip) > >> As long as one is disinteresting in x = inf, NaN, and possibly -0. You >> can do > >> #include <math.h> >> long double >> foo_sqrtl(long double x) >> { >> long double r; >> r = sqrt((double)x); >> return ((r + (x / r))/2); >> } > > I might have done two rounds to be sure. To be sure of what? OP is using cygwin. sqrt() will be a 53-bit double precision result, and OP wants long double sqrtl() which is a 64-bit floating point type. One round would give 106-bit. > Also, the last one should be > > return(x/r+(r-x/r)/2); I beg to differ. #include <stdio.h> #include <math.h> long double foo_sqrtl(long double x) { long double r; r = sqrt((double)x); return ((r + (x / r))/2); } int main(void) { long double x; x = M_PI / M_LN2; printf("%.18Le\n%.18Le\n", sqrtl(x), foo_sqrtl(x)); return (0); } % cc -o foo foo.c -lm && ./foo 2.128934038862452440e+00 2.128934038862452440e+00 > if you might be on a non-base2 system, such as > IBM hex floating point or decimal floating point. OP is using cygwin. -- steve |

Re: sqrtl(), etc. for CygwinThanks for the responses. I thought of "rolling"
my own sqrtl(), but it seemed too much of a detour to also do atan2l(), sinl(), etc. Anyway, my immediate "problem" http://domino.research.ibm.com/Comm/...ember2012.html is now handled. By *pondering* a bit, I realized I only needed a *single* high-precision sqrt(), so I just used 'bc ; scale = 60' ::whack:: James |

Re: sqrtl(), etc. for CygwinSteven G. Kargl <sgk@removetroutmask.apl.washington.edu> wrote:
>> Steven G. Kargl <sgk@removetroutmask.apl.washington.edu> wrote: (snip) >>> #include <math.h> >>> long double >>> foo_sqrtl(long double x) >>> { >>> long double r; >>> r = sqrt((double)x); >>> return ((r + (x / r))/2); >>> } >> I might have done two rounds to be sure. > To be sure of what? OP is using cygwin. sqrt() > will be a 53-bit double precision result, and OP > wants long double sqrtl() which is a 64-bit > floating point type. One round would give > 106-bit. I thought that there were some systems with software 128 bit floating point for long double. Yes that should be fine to get from 53 to 64 bits. >> Also, the last one should be >> return(x/r+(r-x/r)/2); > I beg to differ. (snip) >> if you might be on a non-base2 system, such as >> IBM hex floating point or decimal floating point. > OP is using cygwin. Well, much of GNU libc in general was mentioned in the thread. There seem to be very few hardware implementations of 128 bit floating point, other than IBM (back to the 360/85 and continuing to present day processors) and VAX H-float (microcode on some systems). Single precision sqrt for S/360: DE FR0,BUFF GIVE TWO PASSES OF NEWTON-RAPHSON AU FR0,BUFF ITERATION HER FR0,FR0 DER FR2,FR0 (X/Y1+Y1)/2 = (Y1-X/Y1)/2+X/Y1 TO GUARD AU FR0,ROUND LAST DIGIT-. ADD ROUNDING FUDGE SER FR0,FR2 HER FR0,FR0 AER FR0,FR2 -- glen |

Re: sqrtl(), etc. for CygwinKeith Thompson wrote:
[snip] > gcc doesn't have sqrtl() on any system. It's part of the runtime > library, not the compiler. That's not just a quibble; most or all > Linux-based systems use the GNU C library, but Cygwin apparently uses > something else. [...] Just for my own information and for future reference. Are functions like this sqrtl and other GNU C function OT here? Isn't this group restricted to ANSI and ISO C ? Bill |

All times are GMT. The time now is 11:37 PM. |

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.

SEO by vBSEO ©2010, Crawlability, Inc.