I needed to convert a large integer to and between exponential notation (or e notation), and all questions was about converting from exponential notation.
Which is easy, just enter the number as is, ie. 2.57588E13 and powershell will automatically convert it for you.
However, to get it back might not be obvious and had to resort to C# forums to finally find the answer.
Example:
$bignumber = 2.57588E13
Write-Output "Result: $bignumber"
25758800000000
Write-Output $bignumber.tostring("e5")
2.57588e+013
The "e" is the number of decimals that should be visible in the result. Hope this helps someone else.
Related
please, I am working on a PoC for Person Real-time Identification, and one of the critical aspects of it is to support both minor misspelling and phonetic variations of First, Middle, and Last name. Like HarinGton == HarrinBton or RaphEAl == RafAEl. It's working for longer names, but it's a bit more imprecise for names like Lee and John.
I am using Double Metaphone through dmetaphone() and dmetaphone_alt() in PostgreSQL 13.3 (Supabase.io). And although I appreciate Double Metaphone it has a (too?) short string as the outcome. metaphone() has parameters to make the resulting phonetic representation longer. I investigated dmetaphone() and couldn't find anything other than the default function.
Is there a way of making dmetaphone() and dmetaphone_alt() return a longer phonetic representation similar to metaphone()'s, but with a ALT variation?.
Any help would be much appreciated.
Thanks
Looking at the postgres docs for these features you don't have parametric control over the length of the encoded string for Double Metaphone. In the case of single Metaphone, you can only truncate the output string:
max_output_length sets the maximum length of the output metaphone code; if longer, the output is truncated to this length.
However you may get much better results by using Trigram Similarity or Levenshtein Distance on the encoded output from either of the metaphone methods - this can be a more powerful way to handle phonetic permutations using Metaphones.
Example
Consider all the spelling permutations possible for the artist Cyndi Lauper, using double metaphone with trigram similarity we can achieve 100% similarity between the incorrect string cindy lorper and the correct spelling:
SELECT similarity(dmetaphone('cindy lorper'), dmetaphone('cyndi lauper'));
yields: similarity real: 1 (ie: 100% similarity)
Which means the encodings are identical for both input strings using Double Metaphone. When using Metaphone, they're slightly different. All of the following yield SNTLRPR
SELECT metaphone('cyndy lorper',10);
SELECT metaphone('sinday lorper', 10);
SELECT metaphone('cinday laurper', 10);
SELECT metaphone('cyndi lauper',10);
yields: SNTLPR which is only one character different to SNTLRPR
You can also use Levenshtein Distance to calculate it, which gives you a filterable parameter to work with:
SELECT levenshtein(metaphone('sinday lorper', 10), metaphone('cyndi lauper', 10));
yields: levenshtein integer: 1
It's working for longer names, but it's a bit more imprecise for names
like Lee and John.
It's a bit difficult to see exactly what you're having trouble with - without a more complete reprex.
SELECT similarity(dmetaphone('lee'), dmetaphone('leigh'));
SELECT similarity(dmetaphone('jon'), dmetaphone('john'));
both yield: similarity real: 1 (ie: 100% similarity)
Edit: here's a easy to follow guide for fuzzy matching with postgres
The function solution here works fine.
Suppress or Customize Intro Message in Fish Shell
However I can't seem to insert text as well. Essentially I want to display the fish_logo from OMF, then beneath it my own message.
I thought perhaps to enclose the text in ', or " but I get an error. I tried without any enclosures and got an error.
This is what I thought would work.
function fish_greeting
fish_logo
'Hello Phil. What magic shall we create today?'
end
To output text, use echo thetext.
So
function fish_greeting
fish_logo
echo 'Hello Phil. What magic shall we create today?'
end
Obviously the other user's response is a valid answer to your problem, but I figured I may as well offer you another solution. First off, to explain the root of your problem in detail: You were just putting a quoted string in the function without actually invoking a function, command, or builtin to actually write your desired text to the terminal. Simple enough. The other user suggested you use echo "STRING" which is a completely acceptable response.
However, I would suggest alternatively that you use printf. When writing your scripts it requires a quite different approach to implement printf than it does to use echo, but I know many individuals who would argue that getting familiar with printf is the better option. It may cost being a little trickier to use properly, but it is much more versatile and reliable than echo. I won't bore you even more by documenting every possible manner of using printf as there is PLENTY of documentation, guides, and information out there on the subject.
In your specific case, to achieve the same results as the previous response:
function fish_greeting
fish_logo
printf "%s" "Hello Phil. What magic shall we create today?"
end
This will also, like the echo use case, result in the logo being printed to the terminal via the fish_logo function that fish_greeting invoked followed by your string via printf. A brief explanation of what printf is doing there:
The first quoted value is acting as the format and the following as the argument. Luckily, printf supports a variety of format specifiers for different scenarios. In this case the %s indicates a string, and the argument was passed into that format and written to the terminal output. It's a mouthful... but if you learned anything here then it's totally worth it! And, I personally find it much more rewarding to dig deep in order to garner more experience and knowledge, which will no doubt benefit you in the future.
I'll end this by just showing you a list of printf's format specifiers to give you a glimpse into how much more useful it is than echo:
%d: Argument will be used as decimal integer. (signed or unsigned)
%i: Argument will be used as a signed integer.
%o: An octal unsigned integer.
%u: An unsigned decimal integer.
%x or %X: An unsigned hexadecimal integer.
%f, %g or %G: A floating-point number.
%e or %E: A floating-point number in scientific notation.
%s: A string.
%b: A string that interprets backslash escapes.
%% signifies a literal %.
Besides all of those printf also functions with a large number of recognized backslash escapes, and is just a far superior method of printing than echo! To wrap this up for sure this time: visit the Fish Shell Documentation, and specifically the section for printf to learn more.
Fish Shell Docs
Printf Page
I am using the conversion algorithm of http://lenschulwitz.com/base58 , this perl code.
MANY GOOD CONVERSIONS, AS: 18e559fc6cb0e8de2ce8b50007d474a0d886208e698a07948671e0df520c1525 was converted to 2gBdDRXoLPEhgf9Zd7zw5ujK1qcoPZoendBQJ22VjgqS, all 44 digits.
BAD CONVERSION: 0ab3de5e16675aeb0c4831f5218901fec56f39cc8ad16e5559be4a0ee211f5d0 was converted to in9v3fi1cntD6ERD6QryMJq4r5BncjYZ32xZA6Uj4ST, 43 digits!
other BAD: 00000000000000000000000000000000000000000000000000000000000000d0 to 11111111111111111111111111111114b
What is wrong with the Perl code?
I can use some kind of padding in base58-btc?
PS: I can use something as sudo apt-get install libbase58-0 that is reliable at UBUNTU... But need a Perl interface for it.
Rather than debugging that poorly laid-out code, I suggest that you install Encode::Base58
or
Encode::Base58::GMP
Both of those modules have maintainers who will answer questions if you find you are getting incorrect results
Tested with other conversors, as bs58 js lib, all producing same and consistent results.
It seems XY problem... perhaps the real question is "base58 bitcoin use fixed size representation?" Can I use something as pad 1s?
But it is also part of the answer, not edited the question (reverted) and proced an answer.
... It is a conversion between "incompatible" bases (!), so I think is impossible
... 58=2*29 is not a multiple of 16=2^4... only when digits are multiple of 2... But:
base50("E") = hex("0D"); base58("1E") = hex("000D"); ... the number of padding digits are converted as multiple...
what the problem of cut/add for padding? base50("E") = hex("D"); base58("1E") = hex("D"); base50("E")=hex("000000D"); base50("1111111111E")=hex("D"); ... Not seems a problem, so padding-algorithm (fill 0s or 1s) can be used.
SOLUTION: ok, lets pad, fill 1s when converted have less than 44 digits.
I am currently learning Go and am making a lot of progress. One way I do this is to port past projects and prototypes from a prior language to a new one.
Right now I am busying myself with a "language detector" I prototyped in Python a while ago. In this module, I generate an ngram frequency table, where I then calculate the difference between a given text and a known corpora.
This allows one to effectively determine which corpus is the best match by returning the cosine of two vector representations of the given ngram tables. Yay. Math.
I have a prototype written in Go that works perfectly with plain ascii characters, but I would very much like to have it working with unicode multibyte support. This is where I'm doing my head in.
Here is a quick example of what I'm dealing with: http://play.golang.org/p/2bnAjZX3r0
I've only posted the table generating logic since everything already works just fine.
As you can see by running the snippet, the first text works quite well and builds an accurate table. The second text, which is German, has a few double-byte characters in it. Due to the way I am building the ngram sequence, and due to the fact that these specific runes are made of two bytes, there appear 2 ngrams where the first byte is cut off.
Could someone perhaps post a more efficient solution or, at the very least, guide me through a fix? I'm almost positive I am over analysing this problem.
I plan on open sourcing this package and implementing it as a service using Martini, thus providing a simple API people can use for simple linguistic computation.
As ever, thanks!
If I understand correctly, you want chars in your Parse function to hold the last n characters in the string. Since you're interested in Unicode characters rather than their UTF-8 representation, you might find it easier to manage it as a []rune slice, and only convert back to a string when you have your ngram ready to add to the table. This way you don't need to special case non-ASCII characters in your logic.
Here is a simple modification to your sample program that does the above: http://play.golang.org/p/QMYoSlaGSv
By keeping a circular buffer of runes, you can minimise allocations. Also note that reading a new key from a map returns the zero value (which for int is 0), which means the unknown key check in your code is redundant.
func Parse(text string, n int) map[string]int {
chars := make([]rune, 2 * n)
table := make(map[string]int)
k := 0
for _, chars[k] = range strings.Join(strings.Fields(text), " ") + " " {
chars[n + k] = chars[k]
k = (k + 1) % n
table[string(chars[k:k+n])]++
}
return table
}
I am writing a function that transliterates UNICODE digits into ASCII digits, and I am a bit stumped on what to do if the string contains digits from different sets of UNICODE digits. So for example, if I have the string "\x{2463}\x{24F6}" ("④⓶"). Should my function
return 42?
croak that the string contains mixed sets?
carp that the string contains mixed sets and return 42?
give the user an additional argument to specify one of the three above behaviours?
do something else?
Your current function appears to do #1.
I suggest that you should also write another function to do #4, but only when the requirement appears, and not before .
I'm sure Joel wrote about "premature implementation" in a blog article sometime recently, but I can't find it.
I'm not sure I see a problem.
You support numeric conversion from a range of scripts, which is to say, you are aware of the Unicode codepoints for their numeric characters.
If you find an unknown codepoint in your input data, it is an error.
It is up to you what you do in the event of an error; you may insert a space or underscore, or you may abort conversion. What you would do will depend on the environment in which your function executes; it is not something we can tell you.
My initial thought was #4; strictly based on the fact that I like options. However, I changed my mind, when I viewed your function.
The purpose of the function seems to be, simply, to get the resulting digits 0..9. Users may find it useful to send in mixed sets (a feature :) . I'll use it.
If you ever have to handle input in bases greater than 10, you may end up having to treat many variants on the first 6 letters of the Latin alphabet ('ABCDEF') as digits in all their forms.